From 41a2aee38cf812510010da09de9bae53590ec119 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 27 May 2016 16:23:10 +0200 Subject: Follow the angular styleguide for the directories structure --- client/app/videos/shared/video.model.ts | 63 +++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 client/app/videos/shared/video.model.ts (limited to 'client/app/videos/shared/video.model.ts') diff --git a/client/app/videos/shared/video.model.ts b/client/app/videos/shared/video.model.ts new file mode 100644 index 000000000..eec537c9e --- /dev/null +++ b/client/app/videos/shared/video.model.ts @@ -0,0 +1,63 @@ +export class Video { + id: string; + name: string; + description: string; + magnetUri: string; + podUrl: string; + isLocal: boolean; + thumbnailPath: string; + author: string; + createdDate: Date; + by: string; + duration: string; + + private static createDurationString(duration: number): string { + const minutes = Math.floor(duration / 60); + const seconds = duration % 60; + const minutes_padding = minutes >= 10 ? '' : '0'; + const seconds_padding = seconds >= 10 ? '' : '0'; + + return minutes_padding + minutes.toString() + ':' + seconds_padding + seconds.toString(); + } + + private static createByString(author: string, podUrl: string): string { + let [ host, port ] = podUrl.replace(/^https?:\/\//, '').split(':'); + + if (port === '80' || port === '443') { + port = ''; + } else { + port = ':' + port; + } + + return author + '@' + host + port; + } + + constructor(hash: { + id: string, + name: string, + description: string, + magnetUri: string, + podUrl: string, + isLocal: boolean, + thumbnailPath: string, + author: string, + createdDate: string, + duration: number; + }) { + this.id = hash.id; + this.name = hash.name; + this.description = hash.description; + this.magnetUri = hash.magnetUri; + this.podUrl = hash.podUrl; + this.isLocal = hash.isLocal; + this.thumbnailPath = hash.thumbnailPath; + this.author = hash.author; + this.createdDate = new Date(hash.createdDate); + this.duration = Video.createDurationString(hash.duration); + this.by = Video.createByString(hash.author, hash.podUrl); + } + + isRemovableBy(user): boolean { + return this.isLocal === true && user && this.author === user.username; + } +} -- cgit v1.2.3