Use a MediaQueriesClassifier for consistency.
This commit is contained in:
@@ -5,7 +5,7 @@ import getUnixTime from 'date-fns/getUnixTime';
|
|||||||
import startOfHour from 'date-fns/startOfHour';
|
import startOfHour from 'date-fns/startOfHour';
|
||||||
import { CAMERA_BIRDSEYE } from '../../const';
|
import { CAMERA_BIRDSEYE } from '../../const';
|
||||||
import { CameraConfig, RecordingSegment } from '../../types';
|
import { CameraConfig, RecordingSegment } from '../../types';
|
||||||
import { MediaQueries, MediaQueriesResults } from '../../view';
|
import { MediaQueries, MediaQueriesClassifier, MediaQueriesResults } from '../../view';
|
||||||
import { ViewMedia, ViewMediaClassifier, ViewMediaFactory } from '../../view-media';
|
import { ViewMedia, ViewMediaClassifier, ViewMediaFactory } from '../../view-media';
|
||||||
import { errorToConsole } from '../../utils/basic';
|
import { errorToConsole } from '../../utils/basic';
|
||||||
import { RecordingSegmentsCache } from '../cache';
|
import { RecordingSegmentsCache } from '../cache';
|
||||||
@@ -362,9 +362,9 @@ export class FrigateCameraManagerEngine implements CameraManagerEngine {
|
|||||||
results: MediaQueriesResults,
|
results: MediaQueriesResults,
|
||||||
): boolean {
|
): boolean {
|
||||||
let freshThreshold: number | null = null;
|
let freshThreshold: number | null = null;
|
||||||
if (queries.areEventQueries()) {
|
if (MediaQueriesClassifier.areEventQueries(queries)) {
|
||||||
freshThreshold = EVENT_REQUEST_CACHE_MAX_AGE_SECONDS;
|
freshThreshold = EVENT_REQUEST_CACHE_MAX_AGE_SECONDS;
|
||||||
} else if (queries.areRecordingQueries()) {
|
} else if (MediaQueriesClassifier.areRecordingQueries(queries)) {
|
||||||
freshThreshold = RECORDING_SUMMARY_REQUEST_CACHE_MAX_AGE_SECONDS;
|
freshThreshold = RECORDING_SUMMARY_REQUEST_CACHE_MAX_AGE_SECONDS;
|
||||||
}
|
}
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ import {
|
|||||||
generateMediaViewerContext,
|
generateMediaViewerContext,
|
||||||
} from '../utils/media-to-view';
|
} from '../utils/media-to-view';
|
||||||
import { CameraManager } from '../camera/manager';
|
import { CameraManager } from '../camera/manager';
|
||||||
import { EventMediaQueries, MediaQueries, View } from '../view';
|
import { EventMediaQueries, MediaQueries, MediaQueriesClassifier, View } from '../view';
|
||||||
import { dispatchMessageEvent } from './message.js';
|
import { dispatchMessageEvent } from './message.js';
|
||||||
import './thumbnail.js';
|
import './thumbnail.js';
|
||||||
import { FrigateCardTimelineItem, TimelineDataSource } from '../utils/timeline-source';
|
import { FrigateCardTimelineItem, TimelineDataSource } from '../utils/timeline-source';
|
||||||
@@ -435,7 +435,9 @@ export class FrigateCardTimelineCore extends LitElement {
|
|||||||
* Called whenever the timeline is clicked.
|
* Called whenever the timeline is clicked.
|
||||||
* @param properties The properties of the timeline click event.
|
* @param properties The properties of the timeline click event.
|
||||||
*/
|
*/
|
||||||
protected async _timelineClickHandler(properties: TimelineEventPropertiesResult): Promise<void> {
|
protected async _timelineClickHandler(
|
||||||
|
properties: TimelineEventPropertiesResult,
|
||||||
|
): Promise<void> {
|
||||||
// Calls to stopEventFromActivatingCardWideActions() are included for
|
// Calls to stopEventFromActivatingCardWideActions() are included for
|
||||||
// completeness. Timeline does not support card-wide events and they are
|
// completeness. Timeline does not support card-wide events and they are
|
||||||
// disabled in card.ts in `_getMergedActions`.
|
// disabled in card.ts in `_getMergedActions`.
|
||||||
@@ -496,7 +498,7 @@ export class FrigateCardTimelineCore extends LitElement {
|
|||||||
} else if (
|
} else if (
|
||||||
properties.item &&
|
properties.item &&
|
||||||
properties.what === 'item' &&
|
properties.what === 'item' &&
|
||||||
this.view.query?.areRecordingQueries()
|
MediaQueriesClassifier.areRecordingQueries(this.view.query)
|
||||||
) {
|
) {
|
||||||
const eventView = await this._createViewWithEventMediaQuery(
|
const eventView = await this._createViewWithEventMediaQuery(
|
||||||
this._createEventMediaQuerys(),
|
this._createEventMediaQuerys(),
|
||||||
@@ -525,16 +527,16 @@ export class FrigateCardTimelineCore extends LitElement {
|
|||||||
this.view.queryResults?.hasResults() &&
|
this.view.queryResults?.hasResults() &&
|
||||||
this.view.query
|
this.view.query
|
||||||
) {
|
) {
|
||||||
view = this.view.evolve({
|
view = this.view.evolve({
|
||||||
queryResults: this.view.queryResults
|
queryResults: this.view.queryResults
|
||||||
?.clone()
|
?.clone()
|
||||||
.resetSelectedResult()
|
.resetSelectedResult()
|
||||||
.selectResultIfFound(
|
.selectResultIfFound(
|
||||||
(media) =>
|
(media) =>
|
||||||
!!this.cameras &&
|
!!this.cameras &&
|
||||||
media.getID(this.cameras.get(media.getCameraID())) === properties.item,
|
media.getID(this.cameras.get(media.getCameraID())) === properties.item,
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (view) {
|
if (view) {
|
||||||
@@ -592,7 +594,11 @@ export class FrigateCardTimelineCore extends LitElement {
|
|||||||
// Don't show event thumbnails if the user is looking at recordings,
|
// Don't show event thumbnails if the user is looking at recordings,
|
||||||
// as the recording "hours" are the media, not the event
|
// as the recording "hours" are the media, not the event
|
||||||
// clips/snapshots.
|
// clips/snapshots.
|
||||||
if (this._timeline && this.view && !this.view.query?.areRecordingQueries()) {
|
if (
|
||||||
|
this._timeline &&
|
||||||
|
this.view &&
|
||||||
|
!MediaQueriesClassifier.areRecordingQueries(this.view.query)
|
||||||
|
) {
|
||||||
(
|
(
|
||||||
await this._createViewWithEventMediaQuery(
|
await this._createViewWithEventMediaQuery(
|
||||||
this._createEventMediaQuerys({ window: prefetchedWindow }),
|
this._createEventMediaQuerys({ window: prefetchedWindow }),
|
||||||
@@ -954,7 +960,7 @@ export class FrigateCardTimelineCore extends LitElement {
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
!this.mini &&
|
!this.mini &&
|
||||||
!this.view.query?.areRecordingQueries() &&
|
!MediaQueriesClassifier.areRecordingQueries(this.view.query) &&
|
||||||
freshMediaQuery &&
|
freshMediaQuery &&
|
||||||
!this._alreadyHasAcceptableMediaQuery(freshMediaQuery)
|
!this._alreadyHasAcceptableMediaQuery(freshMediaQuery)
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ import { stopEventFromActivatingCardWideActions } from '../utils/action.js';
|
|||||||
import { contentsChanged } from '../utils/basic.js';
|
import { contentsChanged } from '../utils/basic.js';
|
||||||
import { getFullDependentBrowseMediaQueryParametersOrDispatchError } from '../utils/ha/browse-media.js';
|
import { getFullDependentBrowseMediaQueryParametersOrDispatchError } from '../utils/ha/browse-media.js';
|
||||||
import { ResolvedMediaCache, resolveMedia } from '../utils/ha/resolved-media.js';
|
import { ResolvedMediaCache, resolveMedia } from '../utils/ha/resolved-media.js';
|
||||||
import { MediaQueriesResults, View } from '../view.js';
|
import { MediaQueriesClassifier, MediaQueriesResults, View } from '../view.js';
|
||||||
import { AutoMediaPlugin } from './embla-plugins/automedia.js';
|
import { AutoMediaPlugin } from './embla-plugins/automedia.js';
|
||||||
import { Lazyload } from './embla-plugins/lazyload.js';
|
import { Lazyload } from './embla-plugins/lazyload.js';
|
||||||
import {
|
import {
|
||||||
@@ -372,7 +372,7 @@ export class FrigateCardViewerCarousel extends LitElement {
|
|||||||
// the other media items do).
|
// the other media items do).
|
||||||
!ViewMediaClassifier.isFrigateEvent(media) ||
|
!ViewMediaClassifier.isFrigateEvent(media) ||
|
||||||
!media.hasClip() ||
|
!media.hasClip() ||
|
||||||
!this.view.query?.areEventQueries()
|
!MediaQueriesClassifier.areEventQueries(this.view.query)
|
||||||
) {
|
) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-11
@@ -4,7 +4,6 @@
|
|||||||
// - TODO: Should be able to set live media to 'all' and have it work.
|
// - TODO: Should be able to set live media to 'all' and have it work.
|
||||||
// - TODO: Are there elements of ViewMedia (e.g. getEventCount) that should be moved into subclasses (e.g. a recording subclass).
|
// - TODO: Are there elements of ViewMedia (e.g. getEventCount) that should be moved into subclasses (e.g. a recording subclass).
|
||||||
// - TODO: In MediaQueriesBase, do we need to generic? Just have T be a MediaQuery?
|
// - TODO: In MediaQueriesBase, do we need to generic? Just have T be a MediaQuery?
|
||||||
// - TODO: Are areEventQueries and areRecordingQueries should be in a classifier to keep with the pattern used elsewhere.
|
|
||||||
// - TODO: In the viewer @click handlers should I use this.selected instead of calling carouselScrollPrevious()
|
// - TODO: In the viewer @click handlers should I use this.selected instead of calling carouselScrollPrevious()
|
||||||
|
|
||||||
// Medium:
|
// Medium:
|
||||||
@@ -24,7 +23,6 @@
|
|||||||
// - TODO: What should the timeline do when an event is clicked on that is not in the queryResults (or if queryResults is empty)?
|
// - TODO: What should the timeline do when an event is clicked on that is not in the queryResults (or if queryResults is empty)?
|
||||||
// - TODO: Should the timeline data source clear events (as it currently does) when the query changes?
|
// - TODO: Should the timeline data source clear events (as it currently does) when the query changes?
|
||||||
|
|
||||||
|
|
||||||
import isEqual from 'lodash-es/isEqual';
|
import isEqual from 'lodash-es/isEqual';
|
||||||
import clone from 'lodash-es/clone.js';
|
import clone from 'lodash-es/clone.js';
|
||||||
import cloneDeep from 'lodash-es/cloneDeep.js';
|
import cloneDeep from 'lodash-es/cloneDeep.js';
|
||||||
@@ -52,6 +50,20 @@ export interface ViewParameters extends ViewEvolveParameters {
|
|||||||
camera: string;
|
camera: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class MediaQueriesClassifier {
|
||||||
|
public static areEventQueries(
|
||||||
|
queries?: MediaQueries | null,
|
||||||
|
): queries is EventMediaQueries {
|
||||||
|
return queries instanceof EventMediaQueries;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static areRecordingQueries(
|
||||||
|
queries?: MediaQueries | null,
|
||||||
|
): queries is RecordingMediaQueries {
|
||||||
|
return queries instanceof RecordingMediaQueries;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export class MediaQueriesBase<T extends MediaQuery> {
|
export class MediaQueriesBase<T extends MediaQuery> {
|
||||||
protected _queries: T[] | null = null;
|
protected _queries: T[] | null = null;
|
||||||
|
|
||||||
@@ -69,14 +81,6 @@ export class MediaQueriesBase<T extends MediaQuery> {
|
|||||||
return isEqual(this.getQueries(), that.getQueries());
|
return isEqual(this.getQueries(), that.getQueries());
|
||||||
}
|
}
|
||||||
|
|
||||||
public areEventQueries(): this is EventMediaQueries {
|
|
||||||
return this instanceof EventMediaQueries;
|
|
||||||
}
|
|
||||||
|
|
||||||
public areRecordingQueries(): this is RecordingMediaQueries {
|
|
||||||
return this instanceof RecordingMediaQueries;
|
|
||||||
}
|
|
||||||
|
|
||||||
public getQueries(): T[] | null {
|
public getQueries(): T[] | null {
|
||||||
return this._queries;
|
return this._queries;
|
||||||
}
|
}
|
||||||
@@ -177,7 +181,10 @@ export class MediaQueriesResults {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public selectResult(index: number | null): MediaQueriesResults {
|
public selectResult(index: number | null): MediaQueriesResults {
|
||||||
if (index === null || (this._results && index >= 0 && index < this._results.length)) {
|
if (
|
||||||
|
index === null ||
|
||||||
|
(this._results && index >= 0 && index < this._results.length)
|
||||||
|
) {
|
||||||
this._selectedIndex = index;
|
this._selectedIndex = index;
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
|
|||||||
Reference in New Issue
Block a user