diff options
Diffstat (limited to 'client/src/app/shared/shared-main/video/video-chapters-edit.model.ts')
-rw-r--r-- | client/src/app/shared/shared-main/video/video-chapters-edit.model.ts | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/client/src/app/shared/shared-main/video/video-chapters-edit.model.ts b/client/src/app/shared/shared-main/video/video-chapters-edit.model.ts new file mode 100644 index 000000000..6d7496ed6 --- /dev/null +++ b/client/src/app/shared/shared-main/video/video-chapters-edit.model.ts | |||
@@ -0,0 +1,43 @@ | |||
1 | import { simpleObjectsDeepEqual, sortBy } from '@peertube/peertube-core-utils' | ||
2 | import { VideoChapter } from '@peertube/peertube-models' | ||
3 | |||
4 | export class VideoChaptersEdit { | ||
5 | private chaptersFromAPI: VideoChapter[] = [] | ||
6 | |||
7 | private chapters: VideoChapter[] | ||
8 | |||
9 | loadFromAPI (chapters: VideoChapter[]) { | ||
10 | this.chapters = chapters || [] | ||
11 | |||
12 | this.chaptersFromAPI = chapters | ||
13 | } | ||
14 | |||
15 | patch (values: { [ id: string ]: any }) { | ||
16 | const chapters = values.chapters || [] | ||
17 | |||
18 | this.chapters = chapters.map((c: any) => { | ||
19 | return { | ||
20 | timecode: c.timecode || 0, | ||
21 | title: c.title | ||
22 | } | ||
23 | }) | ||
24 | } | ||
25 | |||
26 | toFormPatch () { | ||
27 | return { chapters: this.chapters } | ||
28 | } | ||
29 | |||
30 | getChaptersForUpdate (): VideoChapter[] { | ||
31 | return this.chapters.filter(c => !!c.title) | ||
32 | } | ||
33 | |||
34 | hasDuplicateValues () { | ||
35 | const timecodes = this.chapters.map(c => c.timecode) | ||
36 | |||
37 | return new Set(timecodes).size !== this.chapters.length | ||
38 | } | ||
39 | |||
40 | shouldUpdateAPI () { | ||
41 | return simpleObjectsDeepEqual(sortBy(this.getChaptersForUpdate(), 'timecode'), this.chaptersFromAPI) !== true | ||
42 | } | ||
43 | } | ||