Add back button.

This commit is contained in:
Dermot Duffy
2021-09-01 07:34:09 -07:00
parent 17572160e7
commit c8788c55dc
2 changed files with 76 additions and 49 deletions
+4 -3
View File
@@ -51,6 +51,7 @@ ha-card .frigate-card-image-list-folder {
box-sizing: border-box; box-sizing: border-box;
text-align: center; text-align: center;
border-style: 2px solid; border-style: 2px solid;
opacity: 0.7;
color: var(--secondary-text-color, white); color: var(--secondary-text-color, white);
border-color: var(--secondary-text-color, black); border-color: var(--secondary-text-color, black);
background-color: var(--primary-background-color, black); background-color: var(--primary-background-color, black);
@@ -86,10 +87,10 @@ webrtc-camera ha-card {
position: absolute; position: absolute;
z-index: 1; z-index: 1;
overflow: hidden; overflow: hidden;
opacity: 0.8; opacity: 0.9;
border-radius: 50%; border-radius: 50%;
top: calc(50% - (54px /2)); top: calc(50% - (48px /2));
height: 54px; height: 48px;
} }
.frigate-media-controls.previous { .frigate-media-controls.previous {
+72 -46
View File
@@ -351,11 +351,9 @@ export class FrigateCard extends LitElement {
} }
// Update the card view. // Update the card view.
protected _changeView( protected _changeView(view?: View | undefined): void {
view?: View | undefined,
): void {
if (view === undefined) { if (view === undefined) {
this._view = new View({view: this.config.view_default}) this._view = new View({ view: this.config.view_default });
} else { } else {
this._view = view; this._view = view;
} }
@@ -514,6 +512,23 @@ export class FrigateCard extends LitElement {
} }
return html` <ul class="mdc-image-list frigate-card-image-list"> return html` <ul class="mdc-image-list frigate-card-image-list">
${this._view.previous
? html`<li class="mdc-image-list__item">
<div class="mdc-image-list__image-aspect-container">
<div class="mdc-image-list__image">
<ha-card
@click=${() => {
this._changeView(this._view.previous);
}}
outlined=""
class="frigate-card-image-list-folder"
>
<ha-icon .icon=${"mdi:arrow-left"}></ha-icon>
</ha-card>
</div>
</div>
</li>`
: ''}
${parent.children.map( ${parent.children.map(
(child, index) => (child, index) =>
html` <li class="mdc-image-list__item"> html` <li class="mdc-image-list__item">
@@ -522,10 +537,13 @@ export class FrigateCard extends LitElement {
? html`<div class="mdc-image-list__image"> ? html`<div class="mdc-image-list__image">
<ha-card <ha-card
@click=${() => { @click=${() => {
this._changeView(new View({ this._changeView(
view: this._view.view, new View({
target: child, view: this._view.view,
previous: this._view})) target: child,
previous: this._view,
}),
);
}} }}
outlined="" outlined=""
class="frigate-card-image-list-folder" class="frigate-card-image-list-folder"
@@ -539,11 +557,14 @@ export class FrigateCard extends LitElement {
class="mdc-image-list__image" class="mdc-image-list__image"
src="${child.thumbnail}" src="${child.thumbnail}"
@click=${() => { @click=${() => {
\ this._changeView(new View({ this._changeView(
view: this._view.is('clips') ? 'clip' : 'snapshot', new View({
target: parent, view: this._view.is('clips') ? 'clip' : 'snapshot',
childIndex: index, target: parent,
previous: this._view})); childIndex: index,
previous: this._view,
}),
);
}} }}
/>`} />`}
</div> </div>
@@ -567,7 +588,7 @@ export class FrigateCard extends LitElement {
case 'live': case 'live':
case 'clips': case 'clips':
case 'snapshots': case 'snapshots':
this._changeView(new View({view: name})); this._changeView(new View({ view: name }));
break; break;
case 'frigate_ui': case 'frigate_ui':
const frigate_url = this._getFrigateURLFromContext(); const frigate_url = this._getFrigateURLFromContext();
@@ -633,7 +654,9 @@ export class FrigateCard extends LitElement {
// From a BrowseMediaSource item extract the first true media item (i.e. a // From a BrowseMediaSource item extract the first true media item (i.e. a
// clip/snapshot, not a folder). // clip/snapshot, not a folder).
protected _getFirstTrueMediaChildIndex(media: BrowseMediaSource | null): number | null { protected _getFirstTrueMediaChildIndex(
media: BrowseMediaSource | null,
): number | null {
if (!media || !media.children) { if (!media || !media.children) {
return null; return null;
} }
@@ -704,7 +727,8 @@ export class FrigateCard extends LitElement {
if (!parent || !parent.children || childIndex == null) { if (!parent || !parent.children || childIndex == null) {
return this._renderAttentionIcon( return this._renderAttentionIcon(
this._view.is('clip') ? 'mdi:filmstrip-off' : 'mdi:camera-off', this._view.is('clip') ? 'mdi:filmstrip-off' : 'mdi:camera-off',
this._view.is('clip') ? 'No recent clip' : 'No recent snapshots'); this._view.is('clip') ? 'No recent clip' : 'No recent snapshots',
);
} }
mediaToRender = parent.children[childIndex]; mediaToRender = parent.children[childIndex];
@@ -739,38 +763,40 @@ export class FrigateCard extends LitElement {
target: parent || undefined, target: parent || undefined,
childIndex: neighbors.previousIndex ?? undefined, childIndex: neighbors.previousIndex ?? undefined,
previous: this._view, previous: this._view,
}) });
}} }}
/>` />`
: ``} : ``}
${this._view.is('clip') ? ${this._view.is('clip')
html`<ha-hls-player ? html`<ha-hls-player
.hass=${this._hass} .hass=${this._hass}
.url=${resolvedMedia.url} .url=${resolvedMedia.url}
class="frigate-card-viewer" class="frigate-card-viewer"
muted muted
controls controls
playsinline playsinline
allow-exoplayer allow-exoplayer
?autoplay="${autoplay}" ?autoplay="${autoplay}"
> >
</ha-hls-player>` </ha-hls-player>`
: html`<img : html`<img
src=${resolvedMedia.url} src=${resolvedMedia.url}
class="frigate-card-viewer" class="frigate-card-viewer"
@click=${() => { @click=${() => {
// Get clips potentially related to this snapshot. // Get clips potentially related to this snapshot.
this._findRelatedClips(mediaToRender).then((relatedClip) => { this._findRelatedClips(mediaToRender).then((relatedClip) => {
if (relatedClip) { if (relatedClip) {
this._changeView(new View({ this._changeView(
view: 'clip', new View({
target: relatedClip, view: 'clip',
previous: this._view, target: relatedClip,
})); previous: this._view,
} }),
}); );
}} }
/>`} });
}}
/>`}
${neighbors?.next ${neighbors?.next
? html`<img ? html`<img
src="${neighbors.next.thumbnail}" src="${neighbors.next.thumbnail}"
@@ -781,7 +807,7 @@ export class FrigateCard extends LitElement {
target: parent || undefined, target: parent || undefined,
childIndex: neighbors.nextIndex ?? undefined, childIndex: neighbors.nextIndex ?? undefined,
previous: this._view, previous: this._view,
}) });
}} }}
/>` />`
: ``} : ``}