@totvs-agro/mobile-components
Version:
Componentes Mobile Totvs (Front-End) para utilização dos estilos do T-Faces e Ionic v3
273 lines (271 loc) • 15.8 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
import { HttpClient } from '@angular/common/http';
import { Component, Input } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';
import { TotvsNotificationType } from '../../providers/totvs-notification-type';
import { ImageViewerController } from 'ionic-img-viewer';
import * as moment from 'moment';
import { ImageUtil } from '../../util/image-util';
import { ImageItemType } from './image-item-type';
import { TotvsNotificationProvider } from '../../providers/totvs-notification-provider';
import { TotvsTranslateProvider } from '../../providers/translate/totvs-translate-provider';
var HTML_TEMPLATE = "<div *ngIf=\"thumbnails\">\n<div class=\"container\" *ngIf=\"imageItemType === typeSlider\">\n <div (click)=\"callImageClick(thumbnail)\" *ngFor=\"let thumbnail of thumbnails; let i = index; let l = last\"\n [ngClass]=\"{ 'mask-first' : i === 0, 'mask' : i != 0 && !l, 'mask-last' : l }\" [style.background-image]=\"getBackground(thumbnail.src)\">\n <p class=\"titulo-da-foto\">\n {{thumbnail.title}}\n </p>\n <span class=\"data\">\n {{dateAsString(thumbnail)}}\n </span>\n <ion-icon class=\"arrow-right\" name=\"ios-arrow-forward\"></ion-icon>\n </div>\n</div>\n<div #containerList class=\"container-list\" *ngIf=\"imageItemType === typeList\">\n <div *ngIf=\"thumbnails.length <= 0 || !thumbnails\">\n <p class=\"no-items\" text-center>{{msgNoItem}}</p>\n </div>\n <ion-grid>\n <ion-row>\n <ion-col col-6 *ngFor=\"let thumbnail of thumbnails\">\n <button icon-only class=\"close-right\" (click)=\"callButtonClick(thumbnail)\">\n <thf-icon name=\"close\" style=\"margin-right: -15px;\"></thf-icon>\n </button>\n <div class=\"mask-grid\" [style.background-image]=\"getBackground(thumbnail.src)\"></div>\n <div class=\"mask-grid-space\" (click)=\"callImageClick(thumbnail)\"></div>\n <div class=\"sk-circle\" *ngIf=\"!isLoadedImage(thumbnail)\">\n <div class=\"sk-circle1 sk-child\"></div>\n <div class=\"sk-circle2 sk-child\"></div>\n <div class=\"sk-circle3 sk-child\"></div>\n <div class=\"sk-circle4 sk-child\"></div>\n <div class=\"sk-circle5 sk-child\"></div>\n <div class=\"sk-circle6 sk-child\"></div>\n <div class=\"sk-circle7 sk-child\"></div>\n <div class=\"sk-circle8 sk-child\"></div>\n <div class=\"sk-circle9 sk-child\"></div>\n <div class=\"sk-circle10 sk-child\"></div>\n <div class=\"sk-circle11 sk-child\"></div>\n <div class=\"sk-circle12 sk-child\"></div>\n </div>\n <ion-label class=\"label-grid\" (click)=\"callLabelClick(thumbnail._id, thumbnail.title)\">\n {{thumbnail.title}}<thf-icon name=\"edit\"></thf-icon>\n </ion-label>\n </ion-col>\n </ion-row>\n </ion-grid>\n</div>\n</div>";
var ImagesItensComponent = /** @class */ (function () {
function ImagesItensComponent(sanitizer, _imageViewerCtrl, _imageUtil, _notificationProvider, _httpClient, _translate) {
this.sanitizer = sanitizer;
this._imageViewerCtrl = _imageViewerCtrl;
this._imageUtil = _imageUtil;
this._notificationProvider = _notificationProvider;
this._httpClient = _httpClient;
this._translate = _translate;
this.typeSlider = ImageItemType.SLIDER;
this.typeList = ImageItemType.LIST;
this.imageItemType = ImageItemType.SLIDER;
this.thumbnails = new Array();
}
ImagesItensComponent.prototype.getBackground = function (image) {
var value = '';
if (this.imageItemType == this.typeSlider) {
value = "linear-gradient(to bottom, rgba(74, 92, 96, 0.2), rgba(29, 36, 38, 0.8)), url(" + image + ")";
}
else {
value = "linear-gradient(to top, rgba(74, 92, 96, 0.2), rgba(29, 36, 38, 0.8)), url(" + image + ")";
}
return this.sanitizer.bypassSecurityTrustStyle(value);
};
ImagesItensComponent.prototype.initializeThumbnails = function () {
return __awaiter(this, void 0, void 0, function () {
var i;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
console.log(this);
this.thumbnails.splice(0, this.thumbnails.length);
i = 0;
_a.label = 1;
case 1:
if (!(i < this.images.length)) return [3 /*break*/, 4];
return [4 /*yield*/, this.generateThumbnailAndPush(this.images[i])];
case 2:
_a.sent();
if (!this.isLoadedImage(this.images[i])) {
//this.getOnlineImage(this.images[i], i);
}
_a.label = 3;
case 3:
i++;
return [3 /*break*/, 1];
case 4: return [2 /*return*/];
}
});
});
};
ImagesItensComponent.prototype.addThumbnail = function (fullImage) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.generateThumbnailAndPush(fullImage)];
case 1:
_a.sent();
return [2 /*return*/];
}
});
});
};
ImagesItensComponent.prototype.generateThumbnailAndPush = function (fullImage, index) {
return __awaiter(this, void 0, void 0, function () {
var thumbnailBase64, newThumbnail;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!!this.isLoadedImage(fullImage)) return [3 /*break*/, 1];
thumbnailBase64 = fullImage.src;
return [3 /*break*/, 3];
case 1: return [4 /*yield*/, this._imageUtil.generateBase64Thumbnail('data:image/*;base64,' + fullImage.src, 200, 200, 1)];
case 2:
thumbnailBase64 = _a.sent();
_a.label = 3;
case 3:
newThumbnail = {
_id: fullImage._id,
src: thumbnailBase64,
title: fullImage.title
};
if (index == undefined)
this.thumbnails.push(newThumbnail);
else
this.thumbnails.splice(index, 1, newThumbnail);
return [2 /*return*/];
}
});
});
};
ImagesItensComponent.prototype.isLoadedImage = function (image) {
if (image.src.indexOf('/assets/') == -1)
return true;
else
return false;
};
ImagesItensComponent.prototype.callImageClick = function (thumbnail) {
if (!this.isLoadedImage(thumbnail)) {
this._notificationProvider.toast(this._translate.instant('COMMON.WAIT_IMAGE_LOADING'), {
type: TotvsNotificationType.WARN
});
return;
}
if (this.imageClick) {
this.imageClick(thumbnail);
}
else {
var fullImage = this.images.find(function (img) { return img._id == thumbnail._id; });
var img = new Image();
img.src = 'data:image/*;base64,' + fullImage.src;
var imageViewer = this._imageViewerCtrl.create(img);
imageViewer.present();
}
};
ImagesItensComponent.prototype.callButtonClick = function (thumbnail) {
if (!this.isLoadedImage(thumbnail)) {
this._notificationProvider.toast(this._translate.instant('COMMON.WAIT_IMAGE_LOADING'), {
type: TotvsNotificationType.WARN
});
return;
}
if (this.callBackButtonClick)
this.callBackButtonClick(thumbnail);
else {
this.removeImage(thumbnail);
}
};
ImagesItensComponent.prototype.removeImage = function (thumbnail, undoCallBack) {
var _this = this;
var thumbIndex = this.thumbnails.findIndex(function (thumb) { return thumb._id == thumbnail._id; });
this.thumbnails.splice(thumbIndex, 1);
var fullImage = this.images.find(function (img) { return img._id == thumbnail._id; });
var imgIndex = this.images.findIndex(function (img) { return img._id == thumbnail._id; });
if (!undoCallBack) { // if you have the callback, the this.images will only be manipulated on the screen
// if you have the callback, the this.images will only be manipulated on the screen
this.images.splice(imgIndex, 1);
}
var msg = this._translate.get('COMMON.X_REMOVED', {
param: this._translate.get('INSPECTION_IMAGES.IMAGE_X', { title: thumbnail.title })
});
this._notificationProvider.toast(msg, {
actionButton: function () {
_this.thumbnails.splice(thumbIndex, 0, thumbnail);
if (undoCallBack)
undoCallBack();
else
_this.images.splice(imgIndex, 0, fullImage);
}
});
};
ImagesItensComponent.prototype.callLabelClick = function (thumbnailId, thumbnailTitle) {
var _this = this;
this._notificationProvider.presentPrompt(this._translate.instant('DETAIL_IMAGEM.ENTER_TITLE_IMAGEM'), [{
name: 'value',
type: 'string',
value: thumbnailTitle
}], [{
text: this._translate.instant('COMMON.CANCEL'),
role: 'cancel',
handler: function (data) {
console.log('Cancel clicked');
}
}, {
text: this._translate.instant('COMMON.CONFIRM'),
handler: function (data) {
if (data.value)
thumbnailTitle = data.value;
_this.thumbnails.find(function (thumb) { return thumb._id == thumbnailId; }).title = thumbnailTitle;
if (_this.callBackEditLabel)
_this.callBackEditLabel(thumbnailId, thumbnailTitle);
}
}]);
};
ImagesItensComponent.prototype.dateAsString = function (image) {
return moment(image.date).format('L');
};
ImagesItensComponent.decorators = [
{ type: Component, args: [{
selector: 'images-itens',
template: HTML_TEMPLATE
},] },
];
//Ver possibilidade de implementar isso no **COMPONENTE**
/*getOnlineImage(imageItem: ImageItemModel, index: number) {
/*this.getImageService(imageItem._id, [])
.then((image: Image[]) => {
this.images[index].src = image[0].encoding;
this.generateThumbnailAndPush(this.images[index], index);
});
}
async getImageService(imageId: string, result: Model[]): Promise<Model[]> {
let response: ApiResponse = await this._httpClient
.get<ApiResponse>(ENV.API_BASE_URL + 'images', {
params: {
id: imageId,
thumbnail: 'false'
}
})
.timeout(AppConfig.TIMEOUT)
.toPromise();
result.push(...response.items);
return result;
}*/
/** @nocollapse */
ImagesItensComponent.ctorParameters = function () { return [
{ type: DomSanitizer, },
{ type: ImageViewerController, },
{ type: ImageUtil, },
{ type: TotvsNotificationProvider, },
{ type: HttpClient, },
{ type: TotvsTranslateProvider, },
]; };
ImagesItensComponent.propDecorators = {
"imageClick": [{ type: Input, args: ['imageClick',] },],
"callBackButtonClick": [{ type: Input, args: ['callBackButtonClick',] },],
"callBackEditLabel": [{ type: Input, args: ['callBackEditLabel',] },],
"images": [{ type: Input, args: ['images',] },],
"imageItemType": [{ type: Input, args: ['imageItemType',] },],
"msgNoItem": [{ type: Input, args: ['msgNoItem',] },],
};
return ImagesItensComponent;
}());
export { ImagesItensComponent };
//# sourceMappingURL=images-itens.js.map