UNPKG

bitfront-library

Version:

Angular CLI project with components and classes used by other Angular projects of the BIT foundation.

192 lines 10.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BitFormUploadComponent = void 0; var core_1 = require("@angular/core"); var fichero_1 = require("../data/fichero"); var bitmessage_1 = require("../data/bitmessage"); var upload_service_1 = require("../service/upload.service"); var message_service_1 = require("../service/message.service"); var i0 = require("@angular/core"); var i1 = require("../service/upload.service"); var i2 = require("../service/message.service"); var i3 = require("@angular/forms"); var i4 = require("@angular/common"); var i5 = require("./bit-upload.component"); function BitFormUploadComponent_div_1_a_1_Template(rf, ctx) { if (rf & 1) { i0.ɵɵelementStart(0, "a", 5); i0.ɵɵtext(1); i0.ɵɵelementEnd(); } if (rf & 2) { var file_r4 = ctx.$implicit; var ctx_r3 = i0.ɵɵnextContext(2); i0.ɵɵpropertyInterpolate("href", ctx_r3.downloadUrl(file_r4.id), i0.ɵɵsanitizeUrl); i0.ɵɵadvance(1); i0.ɵɵtextInterpolate1(" ", file_r4.nombre, " "); } } function BitFormUploadComponent_div_1_Template(rf, ctx) { if (rf & 1) { i0.ɵɵelementStart(0, "div", 3); i0.ɵɵtemplate(1, BitFormUploadComponent_div_1_a_1_Template, 2, 2, "a", 4); i0.ɵɵelementEnd(); } if (rf & 2) { var ctx_r0 = i0.ɵɵnextContext(); i0.ɵɵadvance(1); i0.ɵɵproperty("ngForOf", ctx_r0.fileList); } } function BitFormUploadComponent_div_2_a_1_Template(rf, ctx) { if (rf & 1) { i0.ɵɵelementStart(0, "a", 5); i0.ɵɵtext(1); i0.ɵɵelementEnd(); } if (rf & 2) { var ctx_r6 = i0.ɵɵnextContext(2); i0.ɵɵpropertyInterpolate("href", ctx_r6.downloadUrl(ctx_r6.simpleFile.id), i0.ɵɵsanitizeUrl); i0.ɵɵadvance(1); i0.ɵɵtextInterpolate1(" ", ctx_r6.simpleFile.nombre, " "); } } function BitFormUploadComponent_div_2_span_2_Template(rf, ctx) { if (rf & 1) { i0.ɵɵelementStart(0, "span"); i0.ɵɵtext(1); i0.ɵɵelementEnd(); } if (rf & 2) { var ctx_r7 = i0.ɵɵnextContext(2); i0.ɵɵadvance(1); i0.ɵɵtextInterpolate(ctx_r7.simpleFile.nombre); } } function BitFormUploadComponent_div_2_Template(rf, ctx) { if (rf & 1) { i0.ɵɵelementStart(0, "div", 3); i0.ɵɵtemplate(1, BitFormUploadComponent_div_2_a_1_Template, 2, 2, "a", 6); i0.ɵɵtemplate(2, BitFormUploadComponent_div_2_span_2_Template, 2, 1, "span", 7); i0.ɵɵelementEnd(); } if (rf & 2) { var ctx_r1 = i0.ɵɵnextContext(); i0.ɵɵadvance(1); i0.ɵɵproperty("ngIf", ctx_r1.puedeAbrir); i0.ɵɵadvance(1); i0.ɵɵproperty("ngIf", !ctx_r1.puedeAbrir); } } function BitFormUploadComponent_div_3_Template(rf, ctx) { if (rf & 1) { var _r9 = i0.ɵɵgetCurrentView(); i0.ɵɵelementStart(0, "div", 8); i0.ɵɵelementStart(1, "bit-upload", 9); i0.ɵɵlistener("onFileChange", function BitFormUploadComponent_div_3_Template_bit_upload_onFileChange_1_listener($event) { i0.ɵɵrestoreView(_r9); var ctx_r8 = i0.ɵɵnextContext(); return ctx_r8.fileChange($event); }); i0.ɵɵelementEnd(); i0.ɵɵelementEnd(); } if (rf & 2) { var ctx_r2 = i0.ɵɵnextContext(); i0.ɵɵadvance(1); i0.ɵɵproperty("uploading", ctx_r2.uploading)("reset", ctx_r2.resetUpload)("showFiles", true)("multiple", ctx_r2.multiple)("id", ctx_r2.id); } } var BitFormUploadComponent = /** @class */ (function () { function BitFormUploadComponent(uploadService, messageService, downloadUrlVariable) { this.uploadService = uploadService; this.messageService = messageService; this.downloadUrlVariable = downloadUrlVariable; this.id = "file"; this.puedeAbrir = true; this.onFilesUpload = new core_1.EventEmitter(); this.uploading = false; this.resetUpload = new core_1.EventEmitter(); // para avisar a bitupload de que resetee su formulario BitFormUploadComponent.DOWNLOAD_URL = downloadUrlVariable; } BitFormUploadComponent.prototype.ngOnInit = function () { }; BitFormUploadComponent.prototype.fileChange = function (files) { this.filesToUpload = files; }; // para utilizar desde la propia plantilla BitFormUploadComponent.prototype.downloadUrl = function (id) { return BitFormUploadComponent.getUrlDownloadFile(id); }; // para utilizar desde otro componente BitFormUploadComponent.getUrlDownloadFile = function (id) { return BitFormUploadComponent.DOWNLOAD_URL + "ficheros/download/" + id; }; BitFormUploadComponent.prototype.submit = function () { var _this = this; console.log("submit upload files"); this.uploading = true; this.uploadService.upload(null, this.filesToUpload, this.params).then(function (result) { _this.uploading = false; console.log(result); var jsonArray = eval("(" + result + ")"); //this.messageService.sendNotification(new BitMessage("Informació", "S'ha pujat el fitxer correctament al servidor")); _this.resetUpload.emit(true); //comunicamos a bit-upload que resetee la información de los ficheros cargados _this.onFilesUpload.emit(jsonArray); //comunicamos hacia arriba el resultado satisfactorio de la operación if (_this.multiple) { _this.fileList = jsonArray; } else { _this.simpleFile = jsonArray[0]; } }, function (error) { _this.uploading = false; console.log(error); var objError = JSON.parse(error); _this.messageService.sendNotification(new bitmessage_1.BitMessage("Error", objError.text, undefined, undefined, undefined, bitmessage_1.BitMessage.ERROR)); _this.onFilesUpload.emit(null); _this.fileList = []; _this.simpleFile = null; }); }; BitFormUploadComponent.createNewParamsObject = function (tipoFichero) { var paramsUploadFile = {}; paramsUploadFile["tipoFichero"] = tipoFichero; return paramsUploadFile; }; BitFormUploadComponent.addCarpetaToParamsObject = function (paramsUploadFile, carpeta) { paramsUploadFile["carpeta"] = carpeta; }; BitFormUploadComponent.addIdToParamsObject = function (paramsUploadFile, id) { paramsUploadFile["id"] = id; }; BitFormUploadComponent.addTipoFicheroToParamsObject = function (paramsUploadFile, tipoFichero) { paramsUploadFile["tipoFichero"] = tipoFichero; }; BitFormUploadComponent.ɵfac = function BitFormUploadComponent_Factory(t) { return new (t || BitFormUploadComponent)(i0.ɵɵdirectiveInject(i1.UploadService), i0.ɵɵdirectiveInject(i2.MessageService), i0.ɵɵdirectiveInject("DOWNLOAD_URL")); }; BitFormUploadComponent.ɵcmp = i0.ɵɵdefineComponent({ type: BitFormUploadComponent, selectors: [["bit-form-upload"]], inputs: { params: "params", showFiles: "showFiles", id: "id", multiple: "multiple", searchLabel: "searchLabel", soloLectura: "soloLectura", simpleFile: "simpleFile", fileList: "fileList", puedeAbrir: "puedeAbrir" }, outputs: { onFilesUpload: "onFilesUpload" }, decls: 4, vars: 3, consts: [["method", "post", "enctype", "multipart/form-data", 2, "display", "inline", 3, "submit"], ["class", "col-sm-4", 4, "ngIf"], ["class", "col-sm-8", 4, "ngIf"], [1, "col-sm-4"], ["target", "_blank", 3, "href", 4, "ngFor", "ngForOf"], ["target", "_blank", 3, "href"], ["target", "_blank", 3, "href", 4, "ngIf"], [4, "ngIf"], [1, "col-sm-8"], [3, "uploading", "reset", "showFiles", "multiple", "id", "onFileChange"]], template: function BitFormUploadComponent_Template(rf, ctx) { if (rf & 1) { i0.ɵɵelementStart(0, "form", 0); i0.ɵɵlistener("submit", function BitFormUploadComponent_Template_form_submit_0_listener() { return ctx.submit(); }); i0.ɵɵtemplate(1, BitFormUploadComponent_div_1_Template, 2, 1, "div", 1); i0.ɵɵtemplate(2, BitFormUploadComponent_div_2_Template, 3, 2, "div", 1); i0.ɵɵtemplate(3, BitFormUploadComponent_div_3_Template, 2, 5, "div", 2); i0.ɵɵelementEnd(); } if (rf & 2) { i0.ɵɵadvance(1); i0.ɵɵproperty("ngIf", ctx.fileList != null && ctx.fileList.length > 0 && ctx.showFiles && ctx.multiple); i0.ɵɵadvance(1); i0.ɵɵproperty("ngIf", ctx.simpleFile != null && ctx.showFiles && !ctx.multiple); i0.ɵɵadvance(1); i0.ɵɵproperty("ngIf", !ctx.soloLectura); } }, directives: [i3.ɵangular_packages_forms_forms_ba, i3.NgControlStatusGroup, i3.NgForm, i4.NgIf, i4.NgForOf, i5.BitUploadComponent], encapsulation: 2 }); return BitFormUploadComponent; }()); exports.BitFormUploadComponent = BitFormUploadComponent; (function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(BitFormUploadComponent, [{ type: core_1.Component, args: [{ selector: "bit-form-upload", template: "\n <form method=\"post\" enctype=\"multipart/form-data\" (submit)=\"submit()\" style=\"display: inline;\">\n <div *ngIf=\"fileList != null && fileList.length > 0 && showFiles && multiple\" class=\"col-sm-4\">\n <a *ngFor=\"let file of fileList; let i = index\" target=\"_blank\" href=\"{{ downloadUrl(file.id) }}\">\n {{ file.nombre }}\n </a>\n </div>\n <div *ngIf=\"simpleFile != null && showFiles && !multiple\" class=\"col-sm-4\">\n <a *ngIf=\"puedeAbrir\" target=\"_blank\" href=\"{{ downloadUrl(simpleFile.id) }}\">\n {{ simpleFile.nombre }}\n </a>\n <span *ngIf=\"!puedeAbrir\">{{ simpleFile.nombre }}</span>\n </div>\n <div *ngIf=\"!soloLectura\" class=\"col-sm-8\">\n <bit-upload\n [uploading]=\"uploading\"\n [reset]=\"resetUpload\"\n (onFileChange)=\"fileChange($event)\"\n [showFiles]=\"true\"\n [multiple]=\"multiple\"\n [id]=\"id\"\n >\n </bit-upload>\n </div>\n </form>\n " }] }], function () { return [{ type: i1.UploadService }, { type: i2.MessageService }, { type: undefined, decorators: [{ type: core_1.Inject, args: ["DOWNLOAD_URL"] }] }]; }, { params: [{ type: core_1.Input }], showFiles: [{ type: core_1.Input }], id: [{ type: core_1.Input }], multiple: [{ type: core_1.Input }], searchLabel: [{ type: core_1.Input }], soloLectura: [{ type: core_1.Input }], simpleFile: [{ type: core_1.Input }], fileList: [{ type: core_1.Input }], puedeAbrir: [{ type: core_1.Input }], onFilesUpload: [{ type: core_1.Output }] }); })(); //# sourceMappingURL=bit-form-upload.component.js.map