{"version":3,"file":"downloader.min.js","sources":["downloader.ts"],"sourcesContent":["namespace eXpress.core {\r\n\texport interface IImageRef {\r\n\t\t/** Name (whatever that is...) */\r\n\t\treadonly name: string;\r\n\r\n\t\t/** The absolute URL to fetch a 'medium' representation of the image */\r\n\t\treadonly mediumUrl: string;\r\n\r\n\t\t/** The absolute URL to fetch a 'thumb' representation of the image */\r\n\t\treadonly thumbUrl: string;\r\n\t}\r\n\r\n\texport interface IPhotoImageRef extends IImageRef {\r\n\r\n\t\t/** Width of the raw hires image */\r\n\t\treadonly width: number;\r\n\r\n\t\t/** Height of the raw hires image */\r\n\t\treadonly height: number;\r\n\r\n\t\t/** Date when the photo was taken */\r\n\t\treadonly dateTaken: Date;\r\n\r\n\t\t/** Get State of this photo */\r\n\t\treadonly uploadState: PhotoState;\r\n\r\n\t\t/** Get LastErrorMessage of this photo */\r\n\t\treadonly lastErrorMessage: string;\r\n\r\n\t\t/** Function to set State (and eg clear lastErrorMessage, broadcast event, ...) */\r\n\t\treadonly setState: (uploadState: PhotoState, lastErrorMessage?: string) => void;\r\n\r\n\t\t/** the filesize of the hires image */\r\n\t\treadonly fileSize: number;\r\n\r\n\t\treadonly storeType: StoreType;\r\n\t}\r\n\r\n\texport enum UploadDownloadQueueState {\r\n\t\t/** New UploadDownload queue started */\r\n\t\tStarted,\r\n\r\n\t\t/** Items added to Queue */\r\n\t\tChanged,\r\n\r\n\t\t/** All items are uploaded or downloaded not yet verified */\r\n\t\tLoaded,\r\n\r\n\t\t/** All items are uploaded or downloaded and verified */\r\n\t\tReady\r\n\t}\r\n\r\n\tenum PhotoState {\r\n\t\tNonSmartPhoto = 0,\r\n\t\tUploadQueued = 1,\r\n\t\tUploading = 2,\r\n\t\tUploadFailed = 3,\r\n\t\tUploaded = 4,\r\n\t\tRejected = 5,\r\n\t\tImported = 6,\r\n\t}\r\n\r\n\texport enum DownloadItemStates {\r\n\t\tWaitingForDownload = 0,\r\n\t\tDownloaded = 1,\r\n\t\tDownloadError = 2,\r\n\t\tImported = 3,\r\n\t\tImportError = 4,\r\n\t\tNotFound = 5\r\n\t}\r\n\r\n\t/** For communication with client download and the core.downloader */\r\n\texport interface IDownloadItem {\r\n\t\t/** eXpress mediastore file id*/\r\n\t\treadonly mediastoreFileId: string;\r\n\t\t/** Partner ref id*/\r\n\t\treadonly photoId: string;\r\n\t\treadonly name: string;\r\n\t}\r\n\r\n\texport interface IDownloadQueueItem {\r\n\t\tstate: DownloadItemStates;\r\n\t\terrorMessage?: string;\r\n\t\tdownloadedItem?: core.IDownloadItem;\r\n\t\titemToDownload: core.partners.PartnerPhoto;\r\n\t}\r\n\r\n\texport class Downloader {\r\n\t\tpublic download: services.Download;\r\n\t\tpublic flow: string;\r\n\r\n\t\tpublic progressPopup: ProgressPopup;\r\n\r\n\t\tconstructor(downloadService: services.DownloadService, flow: string, popup: ProgressPopup) {\r\n\t\t\tthis.download = new services.Download(downloadService, this);\r\n\t\t\tthis.flow = flow;\r\n\t\t\tthis.progressPopup = popup;\r\n\t\t}\r\n\r\n\t\t/** Add photo's to the download queue */\r\n\t\tpublic addToQueueAsync(photos: core.partners.PartnerPhoto[]): JQueryPromise {\r\n\t\t\tif (!photos || !photos.length)\r\n\t\t\t\treturn $.Deferred().resolve([]).promise();\r\n\r\n\t\t\tthis.progressPopup.openAsync();\r\n\r\n\t\t\treturn this.download.addToQueueAsync(photos, this.flow)\r\n\t\t\t\t.then(downloadItems => {\r\n\t\t\t\t\treturn downloadItems.map(di => new Photo(\r\n\t\t\t\t\t\tdi.downloadedItem!.mediastoreFileId,\r\n\t\t\t\t\t\tdi.itemToDownload.name,\r\n\t\t\t\t\t\tdi.itemToDownload.dateTaken,\r\n\t\t\t\t\t\tdi.itemToDownload.dateModified,\r\n\t\t\t\t\t\tdi.itemToDownload.dateUploaded,\r\n\t\t\t\t\t\tdi.itemToDownload.description,\r\n\t\t\t\t\t\tdi.itemToDownload.fileSize,\r\n\t\t\t\t\t\tnull,\r\n\t\t\t\t\t\tdi.itemToDownload.height,\r\n\t\t\t\t\t\tdi.itemToDownload.mediumUrl,\r\n\t\t\t\t\t\tdi.itemToDownload.originalFilename,\r\n\t\t\t\t\t\tdi.itemToDownload.thumbUrl,\r\n\t\t\t\t\t\tdi.itemToDownload.width,\r\n\t\t\t\t\t\t0,\r\n\t\t\t\t\t\tdi.itemToDownload.mediumUrl,\r\n\t\t\t\t\t\tnull));\r\n\t\t\t\t})\r\n\t\t\t\t.always(() => this.progressPopup.close(true));\r\n\t\t}\r\n\r\n\t\t// update uploadprogress screen\r\n\t\tpublic handleDownloadItem(totalItems: number, itemsDone: number): void {\r\n\t\t\tconst amount = totalItems + 1 - itemsDone;\r\n\t\t\tthis.progressPopup.updateProgress(amount);\r\n\t\t}\r\n\t}\r\n\r\n\texport type IPhotoSourceItem = core.IPhotoImageRef;\r\n\r\n\texport abstract class PhotoSourceItem implements IPhotoSourceItem {\r\n\r\n\t\tpublic name: string;\r\n\t\tpublic dateTaken: Date;\r\n\t\tpublic uploadState: PhotoState;\r\n\r\n\t\tpublic lastErrorMessage: string;\r\n\t\tpublic width: number;\r\n\t\tpublic height: number;\r\n\t\tpublic thumbUrl: string;\r\n\t\tpublic mediumUrl: string;\r\n\t\tpublic fileSize: number;\r\n\t\tpublic storeType: StoreType;\r\n\r\n\t\tconstructor(name: string, dateTaken: Date, uploadState: PhotoState) {\r\n\t\t\tthis.name = name;\r\n\t\t\tthis.dateTaken = dateTaken;\r\n\t\t\tthis.uploadState = uploadState;\r\n\t\t}\r\n\r\n\t\tpublic setState(uploadState: PhotoState, lastErrorMessage?: string): void {\r\n\t\t\tthis.uploadState = uploadState;\r\n\t\t\tif (lastErrorMessage) {\r\n\t\t\t\tthis.lastErrorMessage = lastErrorMessage;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic abstract loadAsync(): JQueryPromise;\r\n\r\n\t\tpublic toString(): string {\r\n\t\t\treturn \"PhotoImageRef:\" + this.name;\r\n\t\t}\r\n\t}\r\n\r\n\texport class PartnerPhotoSourceItem extends PhotoSourceItem implements IPhotoSourceItem {\r\n\r\n\t\tpublic file: partners.PartnerPhoto;\r\n\t\tpublic orientation: number;\r\n\r\n\t\tconstructor(file: partners.PartnerPhoto) {\r\n\r\n\t\t\tsuper(file.originalFilename, new Date(), PhotoState.NonSmartPhoto);\r\n\r\n\t\t\tthis.file = file;\r\n\t\t\tthis.orientation = 1; // Default: No rotation\r\n\t\t\tthis.width = this.file.width;\r\n\t\t\tthis.height = this.file.height;\r\n\t\t\tthis.mediumUrl = this.file.mediumUrl;\r\n\t\t\tthis.thumbUrl = this.file.thumbUrl;\r\n\t\t\tthis.storeType = this.file.storeType;\r\n\t\t}\r\n\r\n\t\tpublic loadAsync(): JQueryPromise {\r\n\t\t\treturn $.Deferred().resolve().promise();\r\n\t\t}\r\n\r\n\t\tpublic toString(): string {\r\n\t\t\treturn \"PartnerPhotoSourceItem:\" + this.name + \" type:\" + StoreType[this.storeType] + \" url:\" + this.file.downloadUrl;\r\n\t\t}\r\n\t}\r\n}\r\n"],"names":["eXpress","core","UploadDownloadQueueState","PhotoState","DownloadItemStates","Downloader","downloadService","flow","popup","this","download","services","Download","progressPopup","prototype","addToQueueAsync","photos","_this","length","openAsync","then","downloadItems","map","di","Photo","downloadedItem","mediastoreFileId","itemToDownload","name","dateTaken","dateModified","dateUploaded","description","fileSize","height","mediumUrl","originalFilename","thumbUrl","width","always","close","$","Deferred","resolve","promise","handleDownloadItem","totalItems","itemsDone","amount","updateProgress","PhotoSourceItem","uploadState","setState","lastErrorMessage","toString","PartnerPhotoSourceItem","_super","file","call","Date","NonSmartPhoto","orientation","storeType","__extends","loadAsync","StoreType","downloadUrl"],"mappings":"IAAUA,wjBAAV,SAAUA,UAAQ,SAAAC,MAsCjB,IAAYC,yBAcPC,WAUOC,oBAxBAF,yBAAAD,KAAwBC,2BAAxBD,8BAYX,CAAA,IAVAC,yBAAA,QAAA,GAAA,UAGAA,yBAAAA,yBAAA,QAAA,GAAA,UAGAA,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