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.
130 lines
3.8 KiB
130 lines
3.8 KiB
9 years ago
|
// -- copyright
|
||
9 years ago
|
// 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.
|
||
9 years ago
|
// ++
|
||
9 years ago
|
|
||
9 years ago
|
angular
|
||
|
.module('openproject.services')
|
||
9 years ago
|
.factory('wpWatchers', wpWatchers);
|
||
9 years ago
|
|
||
9 years ago
|
function wpWatchers($http, $q) {
|
||
9 years ago
|
|
||
|
var getWatchers = function(path) {
|
||
|
return function() {
|
||
|
var watchers = $q.defer();
|
||
9 years ago
|
|
||
9 years ago
|
$http.get(path).success(function(data) {
|
||
|
watchers.resolve(data._embedded.elements);
|
||
9 years ago
|
|
||
9 years ago
|
}).error(function(err) {
|
||
|
watchers.reject(err);
|
||
|
});
|
||
9 years ago
|
|
||
9 years ago
|
return watchers.promise;
|
||
|
};
|
||
|
};
|
||
|
|
||
9 years ago
|
var watching = function(workPackage) {
|
||
9 years ago
|
var path = workPackage.links.watchers.url();
|
||
|
return getWatchers(path)();
|
||
|
};
|
||
9 years ago
|
|
||
9 years ago
|
var available = function(workPackage) {
|
||
|
var path = workPackage.links.availableWatchers.url();
|
||
|
return getWatchers(path)();
|
||
|
};
|
||
9 years ago
|
|
||
9 years ago
|
var all = function(workPackage) {
|
||
|
var watchers = $q.defer();
|
||
9 years ago
|
|
||
9 years ago
|
$q.all([watching(workPackage), available(workPackage)]).then(function(allWatchers) {
|
||
|
var watching = allWatchers[0],
|
||
|
available = _.filter(allWatchers[1], function(user) {
|
||
|
return _.findIndex(watching, function(watchingUser) {
|
||
|
return user.id === watchingUser.id;
|
||
|
}) === -1;
|
||
9 years ago
|
});
|
||
9 years ago
|
|
||
9 years ago
|
watchers.resolve({ watching: watching, available: available });
|
||
|
|
||
|
}, function(err) {
|
||
|
watchers.reject(err);
|
||
|
});
|
||
|
|
||
|
return watchers.promise;
|
||
|
};
|
||
|
|
||
|
var add = function(workPackage, watcher) {
|
||
|
var added = $q.defer(),
|
||
|
path = workPackage.links.addWatcher.props.href,
|
||
|
method = workPackage.links.addWatcher.props.method,
|
||
|
payload = { user: { href: watcher._links.self.href } };
|
||
|
|
||
|
$http[method](path, payload).then(function() {
|
||
|
added.resolve(watcher);
|
||
|
|
||
|
}, function(err) {
|
||
|
added.reject(err);
|
||
|
});
|
||
|
|
||
|
return added.promise;
|
||
|
};
|
||
|
|
||
|
var remove = function(workPackage, watcher) {
|
||
|
var removed = $q.defer(),
|
||
|
path = workPackage.links.removeWatcher.props.href,
|
||
|
method = workPackage.links.removeWatcher.props.method;
|
||
|
|
||
|
path = path.replace(/\{user\_id\}/, watcher.id);
|
||
|
|
||
|
$http[method](path).then(function() {
|
||
|
removed.resolve(watcher);
|
||
|
|
||
|
}, function(err) {
|
||
|
remove.reject(err);
|
||
|
});
|
||
|
|
||
|
return removed.promise;
|
||
|
};
|
||
9 years ago
|
|
||
9 years ago
|
/*
|
||
9 years ago
|
* NOTE: In theory, this service is independent from WorkPackages,
|
||
9 years ago
|
* however, the only thing currently handled by it is WorkPackage
|
||
|
* related watching.
|
||
|
* This might change in the future, as other Objects are watchable in
|
||
|
* OP - e.g. wiki pages.
|
||
|
*
|
||
|
* The public interface is therefore designed around handling WPs
|
||
|
*/
|
||
9 years ago
|
return {
|
||
9 years ago
|
watchingForWorkPackage: watching,
|
||
9 years ago
|
availableForWorkPackage: available,
|
||
9 years ago
|
forWorkPackage: all,
|
||
9 years ago
|
addForWorkPackage: add,
|
||
|
removeFromWorkPackage: remove
|
||
9 years ago
|
};
|
||
9 years ago
|
}
|