@totvs-agro/mobile-components
Version:
Componentes Mobile Totvs (Front-End) para utilização dos estilos do T-Faces e Ionic v3
100 lines • 5.38 kB
JavaScript
import { Component, Input } from '@angular/core';
import { Events } from 'ionic-angular';
import * as moment from 'moment';
import { TopicsEventsPublishComponents } from '../../util/topics-events-publish-components';
import { TotvsTranslateProvider } from '../../providers/translate/totvs-translate-provider';
var HTML_TEMPLATE = "\n<ion-content padding class=\"background-invite\">\n <button class=\"close-button\" ion-fab (click)='cancel()'>\n <ion-icon name=\"close\"></ion-icon>\n </button>\n <div class=\"invite-content\">\n <p class=\"text-step\">{{stepTitle}} <br> {{countStepFinish}}/{{countSteps}}</p>\n\n <circle-progress [backgroundColor]=\"'#FFFFFF'\" [percent]=\"percent\" [radius]=\"65\" [titleColor]=\"'#225c7f'\" [unitsColor]=\"'#225c7f'\" [outerStrokeColor]=\"'#225c7f'\"\n [showBackground]=\"true\" [animation]=\"false\" [animationDuration]=\"300\" [showSubtitle]=\"false\" [showInnerStroke]=\"false\">\n </circle-progress>\n\n <p *ngIf=\"countStepFinish != countSteps\" class=\"text-time\">{{'COMMON.REMAININGTIME' | tTranslate}}<br/>{{remainingTime}}</p>\n </div>\n</ion-content>";
var LoadProgressComponent = /** @class */ (function () {
function LoadProgressComponent(_events,
//public globalization: GlobalizationServiceProvider,
_translate) {
var _this = this;
this._events = _events;
this._translate = _translate;
this.percent = 0;
this.countStepFinish = 0;
this.timesSteps = [];
/*this.globalization.config(this._translate, () => {
});*/
this.remainingTime = this._translate.instant('COMMON.CALCULATING');
this.stepTitle = this._translate.instant('COMMON.WAIT') + "...";
this._events.subscribe(TopicsEventsPublishComponents.PROGRESS_STEP, function (step) {
_this.stepTitle = step.titleStep;
_this.countStepFinish++;
_this.percent = _this.getPercent();
_this.remainingTimeCalc();
_this.concluded();
});
this.timesSteps = [];
setInterval(function () { return _this.dinamicProgress(); }, 1000);
}
LoadProgressComponent.prototype.getPercent = function () {
return parseInt(((this.countStepFinish / this.countSteps) * 100).toFixed(3));
};
LoadProgressComponent.prototype.getNextPercent = function () {
return parseInt((((this.countStepFinish + 1) / this.countSteps) * 100).toFixed(3));
};
LoadProgressComponent.prototype.remainingTimeCalc = function () {
if (this.lastTimeExecuteStep != undefined) {
var diff = moment(new Date(), "DD/MM/YYYY HH:mm:ss").diff(moment(this.lastTimeExecuteStep, "DD/MM/YYYY HH:mm:ss"));
this.timesSteps.push(diff);
if (this.timesSteps.length == 1) {
diff *= this.countSteps - this.countStepFinish;
}
else {
var average = function (array) { return array.reduce(function (a, b) { return a + b; }) / array.length; };
diff = average(this.timesSteps);
diff *= this.countSteps - this.countStepFinish;
}
this.remainingTime = moment.utc(diff).format(this.formatRemaining(diff));
}
this.lastTimeExecuteStep = new Date();
};
LoadProgressComponent.prototype.dinamicProgress = function () {
var nextPercent = this.getNextPercent();
if (this.percent < nextPercent - 1) {
this.percent++;
}
};
LoadProgressComponent.prototype.formatRemaining = function (time) {
if (time < 60000) {
return "ss [" + this._translate.instant('COMMON.SECOUNDS') + "]";
}
else if (time > 60000 && time < 3600000) {
return "mm [" + this._translate.instant('COMMON.MINUTES') + "] ss [" + this._translate.instant('COMMON.SECOUNDS') + "]";
}
else if (time > 3600000) {
return "HH [" + this._translate.instant('COMMON.HOURS') + "]";
}
};
LoadProgressComponent.prototype.concluded = function () {
if (this.countStepFinish == this.countSteps) {
this._events.unsubscribe(TopicsEventsPublishComponents.PROGRESS_STEP);
this._events.publish(TopicsEventsPublishComponents.PROGRESS_FINISH);
}
};
LoadProgressComponent.prototype.cancel = function () {
this._events.publish(TopicsEventsPublishComponents.PROGRESS_CANCEL);
};
LoadProgressComponent.prototype.ngOnDestroy = function () {
this._events.unsubscribe(TopicsEventsPublishComponents.PROGRESS_FINISH);
console.log('Destroy Componente');
};
LoadProgressComponent.decorators = [
{ type: Component, args: [{
selector: 'load-progress',
template: HTML_TEMPLATE
},] },
];
/** @nocollapse */
LoadProgressComponent.ctorParameters = function () { return [
{ type: Events, },
{ type: TotvsTranslateProvider, },
]; };
LoadProgressComponent.propDecorators = {
"countSteps": [{ type: Input, args: ['countSteps',] },],
};
return LoadProgressComponent;
}());
export { LoadProgressComponent };
//# sourceMappingURL=load-progress.js.map