Commit 5c457902 authored by huriarte's avatar huriarte

Mejoras al upload

parent 3520df12
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
</div> </div>
</div> </div>
<mat-dialog-content> <mat-dialog-content class="none-overflow">
<h4> <h4>
{{'label.file-upload.description' | translate}} {{'label.file-upload.description' | translate}}
</h4> </h4>
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
</mat-form-field> </mat-form-field>
</div> </div>
</div> </div>
<div class="row pt-2"> <div class="row pt-2" *ngIf="createMode">
<div class="col-12"> <div class="col-12">
<mat-form-field class="amd-form-control"> <mat-form-field class="amd-form-control">
<ngx-mat-file-input formControlName="file" [placeholder]="'label.file' | translate" <ngx-mat-file-input formControlName="file" [placeholder]="'label.file' | translate"
...@@ -34,6 +34,16 @@ ...@@ -34,6 +34,16 @@
</mat-form-field> </mat-form-field>
</div> </div>
</div> </div>
<div class="row pt-2" *ngIf="!createMode">
<div class="col-12">
<mat-form-field class="amd-form-control">
<input matInput [placeholder]="'label.file' | translate" formControlName="filename" required>
<mat-icon matSuffix [matTooltip]="'label.file.tooltip' | translate" matTooltipPosition="above">
help_icon
</mat-icon>
</mat-form-field>
</div>
</div>
</form> </form>
</mat-dialog-content> </mat-dialog-content>
......
import { Component, OnInit } from '@angular/core'; import { Component, OnInit, Inject } from '@angular/core';
import { FormGroup, FormBuilder, FormControl, Validators } from '@angular/forms'; import { FormGroup, FormBuilder, FormControl, Validators } from '@angular/forms';
import { HttpEventType, HttpErrorResponse } from '@angular/common/http'; import { HttpEventType, HttpErrorResponse } from '@angular/common/http';
import { of } from 'rxjs'; import { of } from 'rxjs';
import { map, catchError } from 'rxjs/operators'; import { map, catchError } from 'rxjs/operators';
import { AgentService } from '../../../service/agent.service'; import { AgentService } from '../../../service/agent.service';
import { MatDialogRef } from '@angular/material'; import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
import { NotificationService, NotificationType } from '@xdf/commons'; import { NotificationService, NotificationType } from '@xdf/commons';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
...@@ -31,6 +31,8 @@ export class CaFileUploadModalComponent implements OnInit { ...@@ -31,6 +31,8 @@ export class CaFileUploadModalComponent implements OnInit {
enabledOK = false; enabledOK = false;
createMode = true;
fileInfo = new FileUploadModel(); fileInfo = new FileUploadModel();
constructor( constructor(
...@@ -38,12 +40,23 @@ export class CaFileUploadModalComponent implements OnInit { ...@@ -38,12 +40,23 @@ export class CaFileUploadModalComponent implements OnInit {
private agentService: AgentService, private agentService: AgentService,
private _notificationService: NotificationService, private _notificationService: NotificationService,
private _translateService: TranslateService, private _translateService: TranslateService,
public dialogRef: MatDialogRef<CaFileUploadModalComponent> public dialogRef: MatDialogRef<CaFileUploadModalComponent>,
@Inject(MAT_DIALOG_DATA) public data: any
) { ) {
this.formGroup = this.formBuilder.group({ this.formGroup = this.formBuilder.group({
description: new FormControl({ value: "", disabled: false }), description: new FormControl({ value: "", disabled: false }),
file: new FormControl({ value: '', disabled: false }) file: new FormControl({ value: '', disabled: false }),
filename: new FormControl({ value: '', disabled: true })
}); });
if (data) {
this.fileInfo = data;
this.formGroup.controls.description.setValue(this.fileInfo.description);
this.formGroup.controls.filename.setValue(this.fileInfo.filename);
this.createMode = false;
this.enabledOK = true;
}
} }
ngOnInit() { ngOnInit() {
...@@ -72,10 +85,12 @@ export class CaFileUploadModalComponent implements OnInit { ...@@ -72,10 +85,12 @@ export class CaFileUploadModalComponent implements OnInit {
} }
validateFile(file) { validateFile(file) {
const formData = new FormData(); const formData = new FormData();
formData.append('file', file.data); formData.append('file', file.data);
file.inProgress = true; file.inProgress = true;
this.enabledOK = false;
this.agentService.upload(formData).pipe( this.agentService.upload(formData).pipe(
map(event => { map(event => {
......
...@@ -65,6 +65,13 @@ ...@@ -65,6 +65,13 @@
<th mat-header-cell *matHeaderCellDef class="w-actions"></th> <th mat-header-cell *matHeaderCellDef class="w-actions"></th>
<td mat-cell *matCellDef="let element; let $index = index" class="w-actions text-center"> <td mat-cell *matCellDef="let element; let $index = index" class="w-actions text-center">
<div class="btn-group"> <div class="btn-group">
<button type="button" class="btn btn-default btn-sm" (click)="onEditRecord(element, $index)"
[disabled]="!resourceAuth['edit'] || viewMode">
<i class="fa fa-edit"></i>
<span class="visible-md-inline visible-lg-inline visible-xl-inline">
{{'btn.edit' | translate}}
</span>
</button>
<button type="button" class="btn btn-default btn-sm" (click)="onDeleteRecord(element, $index)" <button type="button" class="btn btn-default btn-sm" (click)="onDeleteRecord(element, $index)"
[disabled]="!resourceAuth['delete'] || viewMode"> [disabled]="!resourceAuth['delete'] || viewMode">
<i class="fa fa-trash"></i> <i class="fa fa-trash"></i>
......
...@@ -110,7 +110,8 @@ export class CaFrequentQuestionsComponent implements OnInit { ...@@ -110,7 +110,8 @@ export class CaFrequentQuestionsComponent implements OnInit {
addFile() { addFile() {
let dialog = this.matDialog.open(CaFileUploadModalComponent, { let dialog = this.matDialog.open(CaFileUploadModalComponent, {
width: '500px' width: '500px',
data: null
}); });
dialog.afterClosed().subscribe(result => { dialog.afterClosed().subscribe(result => {
...@@ -123,6 +124,28 @@ export class CaFrequentQuestionsComponent implements OnInit { ...@@ -123,6 +124,28 @@ export class CaFrequentQuestionsComponent implements OnInit {
}); });
} }
onEditRecord(item, index) {
item.editable = true;
let dialog = this.matDialog.open(CaFileUploadModalComponent, {
width: '500px',
data: item
});
dialog.afterClosed().subscribe(result => {
if (result) {
let fileEdited = { ...result };
let listTemp = this.dataSource.data;
listTemp[index] = fileEdited;
this.dataSource.data = listTemp;
}
});
}
saveQuestions(validateForm: boolean) { saveQuestions(validateForm: boolean) {
let success = true; let success = true;
......
...@@ -49,5 +49,6 @@ ...@@ -49,5 +49,6 @@
"label.file-upload.description" : "The question file will be used as material training", "label.file-upload.description" : "The question file will be used as material training",
"label.file" : "File", "label.file" : "File",
"label.file.incompatible.extension" : "Invalid file. Just accept the following file extensions ", "label.file.incompatible.extension" : "Invalid file. Just accept the following file extensions ",
"label.imageAvatar.incompatible.extension" : "Invalid file. Just accept the followeing image types " "label.imageAvatar.incompatible.extension" : "Invalid file. Just accept the followeing image types ",
"label.file.tooltip" : "For security reasones, you cannot edit uploaded files. Please delete and upload a new file"
} }
\ No newline at end of file
...@@ -49,5 +49,6 @@ ...@@ -49,5 +49,6 @@
"label.file-upload.description" : "El archivo de preguntas se utilizará para el entrenamiento del bot", "label.file-upload.description" : "El archivo de preguntas se utilizará para el entrenamiento del bot",
"label.file" : "Archivo", "label.file" : "Archivo",
"label.file.incompatible.extension" : "Archivo no válido. Sólo se aceptan archivos con extensión ", "label.file.incompatible.extension" : "Archivo no válido. Sólo se aceptan archivos con extensión ",
"label.imageAvatar.incompatible.extension" : "Archivo no válido. Sólo se aceptan imágenes y con formato " "label.imageAvatar.incompatible.extension" : "Archivo no válido. Sólo se aceptan imágenes y con formato ",
"label.file.tooltip" : "Por seguridad, no se pueden editar los archivos validados"
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment