Load attachments only if the work package has any (#4561)

pull/4566/head
Alex Dik 9 years ago committed by GitHub
parent 791cbd8922
commit e23b32c495
  1. 32
      frontend/app/components/work-packages/wp-attachments/wp-attachments.directive.ts

@ -27,20 +27,20 @@
//++ //++
import {wpDirectivesModule} from '../../../angular-modules'; import {wpDirectivesModule} from '../../../angular-modules';
import {WpAttachmentsService} from './wp-attachments.service' import {WpAttachmentsService} from './wp-attachments.service';
export class WorkPackageAttachmentsController { export class WorkPackageAttachmentsController {
public workPackage:any; public workPackage:any;
public attachments: Array = []; public attachments:any[] = [];
public fetchingConfiguration:boolean = false; public fetchingConfiguration:boolean = false;
public files: Array<File> = []; public files:File[] = [];
public hasRightToUpload:boolean = false; public hasRightToUpload:boolean = false;
public I18n:any; public I18n:any;
public loading:boolean = false; public loading:boolean = false;
public rejectedFiles: Array = []; public rejectedFiles:any[] = [];
public settings: Object = { public settings = {
maximumFileSize: Number maximumFileSize: Number
}; };
@ -49,14 +49,14 @@ export class WorkPackageAttachmentsController{
private currentlyFocussing; private currentlyFocussing;
private editMode:boolean; private editMode:boolean;
constructor(protected $scope: ng.IScope, constructor(protected $scope:any,
protected $element:ng.IAugmentedJQuery, protected $element:ng.IAugmentedJQuery,
protected $attrs:ng.IAttributes, protected $attrs:ng.IAttributes,
protected wpAttachments:WpAttachmentsService, protected wpAttachments:WpAttachmentsService,
protected NotificationsService: ng.IServiceProvider, protected NotificationsService:any,
protected I18n:any, protected I18n:any,
protected ConfigurationService: ng.IServiceProviderFactory, protected ConfigurationService:any,
protected ConversionService: ng.IServiceProvider){ protected ConversionService:any) {
this.attachments = this.wpAttachments.getCurrentAttachments(); this.attachments = this.wpAttachments.getCurrentAttachments();
this.editMode = $attrs.hasOwnProperty('edit'); this.editMode = $attrs.hasOwnProperty('edit');
@ -70,7 +70,7 @@ export class WorkPackageAttachmentsController{
this.fetchingConfiguration = false; this.fetchingConfiguration = false;
}); });
if(angular.isDefined(this.workPackage)) { if (this.workPackage && this.workPackage.attachments) {
this.loadAttachments(); this.loadAttachments();
} }
@ -104,8 +104,7 @@ export class WorkPackageAttachmentsController{
public remove(file):void { public remove(file):void {
if (this.workPackage.isNew) { if (this.workPackage.isNew) {
_.remove(this.wpAttachments.attachments, file); _.remove(this.wpAttachments.attachments, file);
} } else {
else{
this.wpAttachments.remove(file); this.wpAttachments.remove(file);
} }
}; };
@ -129,10 +128,8 @@ export class WorkPackageAttachmentsController{
public uploadFilteredFiles(files):void { public uploadFilteredFiles(files):void {
this.filterFiles(files); this.filterFiles(files);
this.upload() this.upload();
} }
} }
function wpAttachmentsDirective():ng.IDirective { function wpAttachmentsDirective():ng.IDirective {
@ -148,12 +145,11 @@ function wpAttachmentsDirective(): ng.IDirective {
templateUrl: (element:ng.IAugmentedJQuery, attrs:ng.IAttributes):string => { templateUrl: (element:ng.IAugmentedJQuery, attrs:ng.IAttributes):string => {
if (attrs.hasOwnProperty('edit')) { if (attrs.hasOwnProperty('edit')) {
return '/components/work-packages/wp-attachments/wp-attachments-edit.directive.html'; return '/components/work-packages/wp-attachments/wp-attachments-edit.directive.html';
} } else {
else {
return '/components/work-packages/wp-attachments/wp-attachments.directive.html'; return '/components/work-packages/wp-attachments/wp-attachments.directive.html';
} }
} }
} };
} }
wpDirectivesModule.directive('wpAttachments', wpAttachmentsDirective); wpDirectivesModule.directive('wpAttachments', wpAttachmentsDirective);

Loading…
Cancel
Save