kanbanworkflowstimelinescrumrubyroadmapproject-planningproject-managementopenprojectangularissue-trackerifcgantt-chartganttbug-trackerboardsbcf
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
198 lines
6.5 KiB
198 lines
6.5 KiB
9 years ago
|
//-- copyright
|
||
|
// OpenProject is a project management system.
|
||
|
// Copyright (C) 2012-2015 the OpenProject Foundation (OPF)
|
||
|
//
|
||
|
// This program is free software; you can redistribute it and/or
|
||
|
// modify it under the terms of the GNU General Public License version 3.
|
||
|
//
|
||
|
// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
|
||
|
// Copyright (C) 2006-2013 Jean-Philippe Lang
|
||
|
// Copyright (C) 2010-2013 the ChiliProject Team
|
||
|
//
|
||
|
// This program is free software; you can redistribute it and/or
|
||
|
// modify it under the terms of the GNU General Public License
|
||
|
// as published by the Free Software Foundation; either version 2
|
||
|
// of the License, or (at your option) any later version.
|
||
|
//
|
||
|
// This program is distributed in the hope that it will be useful,
|
||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
// GNU General Public License for more details.
|
||
|
//
|
||
|
// You should have received a copy of the GNU General Public License
|
||
|
// along with this program; if not, write to the Free Software
|
||
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
//
|
||
|
// See doc/COPYRIGHT.rdoc for more details.
|
||
|
//++
|
||
|
|
||
8 years ago
|
import {wpDirectivesModule} from '../../angular-modules';
|
||
9 years ago
|
import {WpAttachmentsService} from './wp-attachments.service';
|
||
8 years ago
|
import {WorkPackageNotificationService} from '../wp-edit/wp-notification.service';
|
||
|
import {scopedObservable} from '../../helpers/angular-rx-utils';
|
||
|
import {WorkPackageCacheService} from '../work-packages/work-package-cache.service';
|
||
|
import {WorkPackageResourceInterface} from '../api/api-v3/hal-resources/work-package-resource.service';
|
||
|
import {CollectionResourceInterface} from '../api/api-v3/hal-resources/collection-resource.service';
|
||
9 years ago
|
|
||
9 years ago
|
export class WorkPackageAttachmentsController {
|
||
8 years ago
|
public workPackage:any;
|
||
8 years ago
|
public wpSingleViewCtrl;
|
||
8 years ago
|
public hideEmptyFields:boolean;
|
||
9 years ago
|
|
||
8 years ago
|
public attachments:any[] = [];
|
||
|
public fetchingConfiguration:boolean = false;
|
||
|
public files:File[] = [];
|
||
|
public hasRightToUpload:boolean = false;
|
||
|
public loading:boolean = false;
|
||
|
public rejectedFiles:any[] = [];
|
||
9 years ago
|
|
||
9 years ago
|
public settings = {
|
||
9 years ago
|
maximumFileSize: Number
|
||
9 years ago
|
};
|
||
9 years ago
|
|
||
8 years ago
|
public size:any;
|
||
9 years ago
|
|
||
9 years ago
|
private currentlyFocussing;
|
||
9 years ago
|
|
||
8 years ago
|
constructor(protected $scope:any,
|
||
|
protected $element:ng.IAugmentedJQuery,
|
||
8 years ago
|
protected wpCacheService:WorkPackageCacheService,
|
||
8 years ago
|
protected wpAttachments:WpAttachmentsService,
|
||
|
protected NotificationsService:any,
|
||
8 years ago
|
protected wpNotificationsService:WorkPackageNotificationService,
|
||
8 years ago
|
protected I18n:any,
|
||
|
protected ConfigurationService:any,
|
||
|
protected ConversionService:any) {
|
||
9 years ago
|
|
||
9 years ago
|
this.workPackage = $scope.vm.workPackage();
|
||
9 years ago
|
|
||
8 years ago
|
this.attachments = this.workPackage.isNew ? wpAttachments.pendingAttachments : this.attachments;
|
||
|
if (angular.isDefined($scope.vm.wpSingleViewCtrl)) {
|
||
|
$scope.vm.wpSingleViewCtrl.attachments = this.attachments;
|
||
|
}
|
||
|
|
||
9 years ago
|
this.hasRightToUpload = !!(angular.isDefined(this.workPackage.addAttachment) || this.workPackage.isNew);
|
||
9 years ago
|
|
||
9 years ago
|
this.fetchingConfiguration = true;
|
||
|
ConfigurationService.api().then(settings => {
|
||
|
this.settings.maximumFileSize = settings.maximumAttachmentFileSize;
|
||
|
this.fetchingConfiguration = false;
|
||
|
});
|
||
9 years ago
|
|
||
|
if (this.workPackage && this.workPackage.attachments) {
|
||
8 years ago
|
this.loadAttachments(false);
|
||
9 years ago
|
}
|
||
9 years ago
|
|
||
8 years ago
|
$scope.$on('work_packages.attachment.add', (evt, file) => {
|
||
8 years ago
|
this.attachments.push(file);
|
||
|
});
|
||
8 years ago
|
|
||
8 years ago
|
if (this.workPackage.isNew) {
|
||
|
this.attachments = this.wpAttachments.pendingAttachments;
|
||
|
this.registerCreateObserver();
|
||
|
} else {
|
||
|
this.registerEditObserver();
|
||
8 years ago
|
}
|
||
9 years ago
|
}
|
||
9 years ago
|
|
||
8 years ago
|
private registerEditObserver() {
|
||
|
scopedObservable(this.$scope, this.wpCacheService.loadWorkPackage(this.workPackage.id))
|
||
|
.subscribe((wp:WorkPackageResourceInterface) => {
|
||
|
this.workPackage = wp;
|
||
|
this.loadAttachments(true);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
private registerCreateObserver() {
|
||
|
scopedObservable(this.$scope, this.wpCacheService.onNewWorkPackage())
|
||
|
.subscribe((wp:WorkPackageResourceInterface) => {
|
||
|
this.wpAttachments.uploadPendingAttachments(wp).then(() => {
|
||
|
// Reload the work package after attachments are uploaded to
|
||
|
// provide the correct links, in e.g., the description
|
||
|
this.wpCacheService.loadWorkPackage(<number> wp.id, true);
|
||
8 years ago
|
});
|
||
8 years ago
|
});
|
||
|
}
|
||
|
|
||
8 years ago
|
public upload():void {
|
||
9 years ago
|
if (this.workPackage.isNew) {
|
||
|
this.files.forEach((file) => {
|
||
|
this.attachments.push(file);
|
||
9 years ago
|
});
|
||
9 years ago
|
return;
|
||
|
}
|
||
|
|
||
|
if (this.files.length > 0) {
|
||
|
this.wpAttachments.upload(this.workPackage, this.files).then(() => {
|
||
|
this.files = [];
|
||
8 years ago
|
this.workPackage.updateAttachments();
|
||
9 years ago
|
});
|
||
|
}
|
||
|
};
|
||
|
|
||
8 years ago
|
public loadAttachments(refresh:boolean = true):ng.IPromise<any> {
|
||
8 years ago
|
this.loading = true;
|
||
8 years ago
|
return this.workPackage.attachments.$load(refresh)
|
||
|
.then((collection:CollectionResourceInterface) => {
|
||
8 years ago
|
this.attachments.length = 0;
|
||
|
angular.extend(this.attachments, collection.elements);
|
||
8 years ago
|
})
|
||
|
.finally(() => {
|
||
9 years ago
|
this.loading = false;
|
||
|
});
|
||
8 years ago
|
}
|
||
9 years ago
|
|
||
8 years ago
|
public remove(file):void {
|
||
8 years ago
|
if (!this.workPackage.isNew) {
|
||
|
if (file._type === 'Attachment') {
|
||
|
file.delete()
|
||
8 years ago
|
.then(() => this.workPackage.updateAttachments())
|
||
8 years ago
|
.catch(error => {
|
||
|
this.wpNotificationsService.handleErrorResponse(error, this.workPackage);
|
||
|
});
|
||
|
}
|
||
9 years ago
|
}
|
||
8 years ago
|
_.pull(this.attachments, file);
|
||
8 years ago
|
}
|
||
9 years ago
|
|
||
8 years ago
|
public focus(attachment:any):void {
|
||
9 years ago
|
this.currentlyFocussing = attachment;
|
||
|
};
|
||
|
|
||
8 years ago
|
public focussing(attachment:any):boolean {
|
||
9 years ago
|
return this.currentlyFocussing === attachment;
|
||
|
};
|
||
9 years ago
|
|
||
8 years ago
|
public filterFiles(files):void {
|
||
9 years ago
|
// Directories cannot be uploaded and as such, should not become files in
|
||
|
// the sense of this directive. The files within the directories will
|
||
|
// be taken though.
|
||
8 years ago
|
_.remove(files, (file:any) => {
|
||
9 years ago
|
return file.type === 'directory';
|
||
9 years ago
|
});
|
||
9 years ago
|
};
|
||
9 years ago
|
|
||
8 years ago
|
public uploadFilteredFiles(files):void {
|
||
9 years ago
|
this.filterFiles(files);
|
||
9 years ago
|
this.upload();
|
||
9 years ago
|
}
|
||
9 years ago
|
}
|
||
|
|
||
8 years ago
|
function wpAttachmentsDirective():ng.IDirective {
|
||
9 years ago
|
return {
|
||
9 years ago
|
bindToController: true,
|
||
|
controller: WorkPackageAttachmentsController,
|
||
|
controllerAs: 'vm',
|
||
9 years ago
|
replace: true,
|
||
9 years ago
|
restrict: 'E',
|
||
9 years ago
|
scope: {
|
||
9 years ago
|
workPackage: '&',
|
||
8 years ago
|
hideEmptyFields: '=',
|
||
|
wpSingleViewCtrl: '='
|
||
8 years ago
|
},
|
||
8 years ago
|
templateUrl: '/components/wp-attachments/wp-attachments.directive.html'
|
||
9 years ago
|
};
|
||
9 years ago
|
}
|
||
|
|
||
9 years ago
|
wpDirectivesModule.directive('wpAttachments', wpAttachmentsDirective);
|