OpenProject is the leading open source project management software.
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.
openproject/frontend/app/components/routing/wp-view-base/wp-view-base.controller.ts

119 lines
4.3 KiB

//-- 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.
//++
import {WorkPackageResourceInterface} from '../../api/api-v3/hal-resources/work-package-resource.service';
import {scopedObservable} from '../../../helpers/angular-rx-utils';
import {WorkPackageCacheService} from '../../work-packages/work-package-cache.service';
import {KeepTabService} from '../../wp-panels/keep-tab/keep-tab.service';
import {wpControllersModule} from '../../../angular-modules';
import {WorkPackageEditModeStateService} from '../../wp-edit/wp-edit-mode-state.service';
export class WorkPackageViewController {
protected $q:ng.IQService;
protected $state:ng.ui.IStateService;
protected $rootScope:ng.IRootScopeService;
protected keepTab:KeepTabService;
protected wpCacheService:WorkPackageCacheService;
protected wpEditModeState:WorkPackageEditModeStateService;
protected WorkPackageService;
protected PathHelper:op.PathHelper;
protected I18n:op.I18n;
// Helper promise to detect when the controller has been initialized
// (when a WP has loaded).
public initialized:ng.IPromise<any>;
// Work package resource to be loaded from the cache
public workPackage:WorkPackageResourceInterface;
public projectIdentifier:string;
public focusAnchorLabel:string;
public showStaticPagePath:string;
constructor(public $injector, public $scope, protected workPackageId) {
this.$inject('$q', '$state', 'keepTab', 'wpCacheService', 'WorkPackageService',
'wpEditModeState', 'PathHelper', 'I18n');
var deferred = this.$q.defer();
this.initialized = deferred.promise;
scopedObservable($scope, this.wpCacheService.loadWorkPackage(workPackageId))
.subscribe((wp:WorkPackageResourceInterface) => {
this.workPackage = wp;
deferred.resolve();
});
}
protected $inject(...args:string[]) {
args.forEach(field => {
this[field] = this.$injector.get(field);
});
}
/**
* Initialize controller after workPackage resource has been loaded.
*/
protected init() {
// Ensure the schema is being loaded as soon as possible
this.workPackage.schema.$load();
// Set elements
this.projectIdentifier = this.workPackage.project.identifier;
// Preselect this work package for future list operations
this.showStaticPagePath = this.PathHelper.workPackagePath(this.workPackage);
this.WorkPackageService.cache().put('preselectedWorkPackageId', this.workPackage.id);
// Listen to tab changes to update the tab label
scopedObservable(this.$scope, this.keepTab.observable).subscribe((tabs:any) => {
this.updateFocusAnchorLabel(tabs.active);
});
}
/**
* Recompute the current tab focus label
*/
public updateFocusAnchorLabel(tabName:string):string {
const tabLabel = this.I18n.t('js.label_work_package_details_you_are_here', {
tab: this.I18n.t('js.work_packages.tabs.' + tabName),
type: this.workPackage.type.name,
subject: this.workPackage.subject
});
return this.focusAnchorLabel = tabLabel;
}
public get canViewWorkPackageWatchers() {
return !!(this.workPackage && this.workPackage.watchers);
}
}
wpControllersModule.controller('WorkPackageViewController', WorkPackageViewController);