Skip to content

Commit 5e1d337

Browse files
committed
Merge branch 'develop' - Preparing for v3.2 release
2 parents 3fb2e11 + 8b902b8 commit 5e1d337

File tree

153 files changed

+6195
-743
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

153 files changed

+6195
-743
lines changed

.jshintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"expect",
3434
"inject",
3535
"jasmine",
36+
"fixture",
3637
"spyOn",
3738
"describe",
3839
"beforeEach",

app/app.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ var backendUrl = window.ushahidi.backendUrl = window.ushahidi.backendUrl || proc
5151
'config',
5252
'messages',
5353
'notifications',
54-
'contacts'
54+
'contacts',
55+
'roles',
56+
'permissions',
57+
'csv'
5558
];
5659

5760
angular.module('app',

app/common/common-module.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,21 @@ angular.module('ushahidi.common', [
1212

1313
.service('Authentication', require('./services/authentication.js'))
1414
.service('Session', require('./services/session.js'))
15+
1516
.service('ConfigEndpoint', require('./services/endpoints/config.js'))
1617
.service('UserEndpoint', require('./services/endpoints/user-endpoint.js'))
1718
.service('FormEndpoint', require('./services/endpoints/form.js'))
1819
.service('FormAttributeEndpoint', require('./services/endpoints/form-attributes.js'))
1920
.service('FormStageEndpoint', require('./services/endpoints/form-stages.js'))
2021
.service('TagEndpoint', require('./services/endpoints/tag.js'))
22+
.service('RoleEndpoint', require('./services/endpoints/role.js'))
23+
.service('PermissionEndpoint', require('./services/endpoints/permission.js'))
2124
.service('DataProviderEndpoint', require('./services/endpoints/data-providers.js'))
22-
.service('FontAwesomeIcons', require('./services/endpoints/FontAwesomeIcons.js'))
23-
.service('RoleHelper', require('./services/role-helper.js'))
25+
2426
.service('PostViewHelper', require('./services/view-helper.js'))
2527
.service('Config', require('./services/config.js'))
2628
.service('Util', require('./services/util.js'))
29+
.service('DataRetriever', require('./services/data-retriever.js'))
2730
.service('Notify', require('./services/notify.js'))
2831
.service('multiTranslate', require('./services/multi-translate.js'))
2932
.service('GlobalFilter', require('./services/global-filter.js'))
@@ -33,11 +36,14 @@ angular.module('ushahidi.common', [
3336
.service('Registration', require('./services/registration.js'))
3437
.service('PasswordReset', require('./services/password-reset.js'))
3538
.service('IconManager', require('./services/icon-manager.js'))
39+
.service('FontAwesomeIcons', require('./services/endpoints/FontAwesomeIcons.js'))
3640

3741
.controller('navigation', require('./controllers/navigation.js'))
3842
.controller('PageMetadata', require('./controllers/page-metadata.js'))
3943
.controller('notifier', require('./controllers/notifier.js'))
4044

45+
.directive('collectionSelector', require('./directives/collection-selector.js'))
46+
.directive('roleSelector', require('./directives/role-selector.js'))
4147
.directive('iconPicker', require('./directives/iconpicker.js'))
4248
.directive('firstTimeConfig', require('./directives/first-time-config.js'))
4349

app/common/controllers/login-controller.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,30 @@ function (
1616
$scope.$emit('setPageTitle', title);
1717
});
1818

19-
function clearLoginForm() {
19+
$scope.clearLoginForm = function () {
2020
$scope.failed = true;
2121
$scope.processing = false;
2222
$scope.email = '';
2323
$scope.password = '';
24-
}
24+
};
2525

26-
function finishedLogin() {
26+
$scope.finishedLogin = function () {
2727
$scope.failed = false;
2828
$scope.processing = false;
29-
}
29+
};
3030

3131
$scope.loginSubmit = function () {
3232
$scope.processing = true;
3333

3434
Authentication
3535
.login($scope.email, $scope.password)
36-
.then(finishedLogin, clearLoginForm);
36+
.then($scope.finishedLogin, $scope.clearLoginForm);
3737
};
3838

3939
// If we're already logged in
4040
if ($rootScope.loggedin) {
4141
$location.url('/');
4242
}
4343

44-
finishedLogin();
44+
$scope.finishedLogin();
4545
}];

app/common/controllers/navigation.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ function (
1616
// Start with preloaded config
1717
$scope.site = BootstrapConfig;
1818
// Then update from server
19-
var reloadSiteConfig = function () {
19+
$scope.reloadSiteConfig = function () {
2020
ConfigEndpoint.get({ id: 'site' }).$promise.then(function (site) {
2121
$scope.site = site;
2222
});
2323
};
2424

2525
$rootScope.$on('event:update:header', function () {
26-
reloadSiteConfig();
26+
$scope.reloadSiteConfig();
2727
});
2828

2929
$rootScope.$on('$routeChangeSuccess', function (ev, current) {
@@ -36,7 +36,7 @@ function (
3636
}
3737
});
3838

39-
reloadSiteConfig();
39+
$scope.reloadSiteConfig();
4040

4141
// @todo: Integrate the modal state controller into a globally accessible
4242
// directive which binds the same logic but does not effect markup.
@@ -48,11 +48,20 @@ function (
4848
$scope.collectionOpen.data = !$scope.collectionOpen.data;
4949
};
5050

51+
$scope.canCreatePost = function () {
52+
return $scope.loggedin || !$scope.site.private;
53+
};
54+
55+
$scope.canRegister = function () {
56+
return !$scope.site.private;
57+
};
5158

5259
$scope.logoutClick = function (e) {
5360
e.preventDefault();
5461
e.stopPropagation();
5562
Authentication.logout();
5663
};
5764

65+
66+
5867
}];

app/common/controllers/page-metadata.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ function (
1919
$scope.pageRobots = null;
2020

2121
// Then update from server
22-
var reloadSiteConfig = function () {
22+
$scope.reloadSiteConfig = function () {
2323
ConfigEndpoint.get({ id: 'site' }).$promise.then(function (site) {
2424
$scope.siteTitle = site.name ? site.name : USHAHIDI;
2525
});
2626
};
2727

2828
$rootScope.$on('event:update:header', function () {
29-
reloadSiteConfig();
29+
$scope.reloadSiteConfig();
3030
});
31-
reloadSiteConfig();
31+
$scope.reloadSiteConfig();
3232

3333
$rootScope.$on('setPageTitle', function (event, title) {
3434
$scope.pageTitle = null;
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/**
2+
* Ushahidi Angular Collection Selector directive
3+
* Drop in directive for managing collections addition for posts
4+
*/
5+
6+
module.exports = [
7+
function (
8+
) {
9+
var controller = [
10+
'$scope',
11+
'$rootScope',
12+
'$translate',
13+
'Notify',
14+
'CollectionEndpoint',
15+
'_',
16+
function (
17+
$scope,
18+
$rootScope,
19+
$translate,
20+
Notify,
21+
CollectionEndpoint,
22+
_
23+
) {
24+
$scope.showNewCollectionInput = false;
25+
$scope.newCollection = '';
26+
$scope.editableCollections = [];
27+
28+
$scope.refreshCollections = function () {
29+
CollectionEndpoint.editableByMe().$promise.then(function (results) {
30+
$scope.editableCollections = results;
31+
});
32+
};
33+
34+
$scope.refreshCollections();
35+
36+
$scope.$on('event:collection-selector:update', function () {
37+
$scope.refrehCollections();
38+
});
39+
40+
$scope.postInCollection = function (collection) {
41+
return _.contains($scope.post.sets, String(collection.id));
42+
};
43+
44+
$scope.toggleCreateCollection = function () {
45+
$scope.showNewCollectionInput = !$scope.showNewCollectionInput;
46+
};
47+
48+
$scope.toggleCollection = function (selectedCollection) {
49+
if (_.contains($scope.post.sets, String(selectedCollection.id))) {
50+
$scope.removeFromCollection(selectedCollection);
51+
} else {
52+
$scope.addToCollection(selectedCollection);
53+
}
54+
};
55+
56+
$scope.addToCollection = function (selectedCollection) {
57+
var collectionId = selectedCollection.id, collection = selectedCollection.name;
58+
59+
CollectionEndpoint.addPost({'collectionId': collectionId, 'id': $scope.post.id})
60+
.$promise.then(function () {
61+
$translate('notify.collection.add_to_collection', {collection: collection})
62+
.then(function (message) {
63+
$scope.post.sets.push(String(collectionId));
64+
Notify.showNotificationSlider(message);
65+
});
66+
}, function (errorResponse) {
67+
Notify.showApiErrors(errorResponse);
68+
});
69+
};
70+
71+
$scope.removeFromCollection = function (selectedCollection) {
72+
var collectionId = selectedCollection.id, collection = selectedCollection.name;
73+
74+
CollectionEndpoint.removePost({'collectionId': collectionId, 'id': $scope.post.id})
75+
.$promise
76+
.then(function () {
77+
$translate('notify.collection.removed_from_collection', {collection: collection})
78+
.then(function (message) {
79+
$scope.post.sets = _.without($scope.post.sets, String(collectionId));
80+
Notify.showNotificationSlider(message);
81+
});
82+
}, function (errorResponse) {
83+
Notify.showApiErrors(errorResponse);
84+
});
85+
};
86+
/*
87+
scope.searchCollections = function (query) {
88+
CollectionEndpoint.query(query)
89+
.$promise
90+
.then(function (result) {
91+
}, function (errorResponse) {
92+
Notify.showApiErrors(errorResponse);
93+
});
94+
};
95+
96+
scope.clearSearch = function() {
97+
scope.editableCollection = scope.editableCollectionCopy;
98+
};
99+
*/
100+
$scope.createNewCollection = function (collectionName) {
101+
var collection = {
102+
'name': collectionName,
103+
'user_id': $rootScope.currentUser.userId
104+
};
105+
CollectionEndpoint.save(collection)
106+
.$promise
107+
.then(function (collection) {
108+
$scope.toggleCreateCollection();
109+
$scope.newCollection = '';
110+
$scope.addToCollection(collection);
111+
112+
// Where collection selectors can appear multiple times
113+
// it is necessary to force a collection refresh when an update occurs
114+
// on anyone collection selector - to ensure that newly created collections
115+
// are available in all lists on the page.
116+
// TODO: add caching for collections to reduce requests.
117+
$rootScope.$broadcast('event:collection:update');
118+
}, function (errorResponse) {
119+
Notify.showApiErrors(errorResponse);
120+
});
121+
};
122+
123+
}];
124+
return {
125+
restrict: 'E',
126+
templateUrl: 'templates/collection-selector/collection-selector.html',
127+
scope: {
128+
post: '='
129+
},
130+
controller: controller
131+
};
132+
}];

app/common/directives/file-upload.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ angular.module('ushahidi.common.file-upload', [])
99
},
1010

1111
controller: [
12-
'$scope',
12+
'$scope', '$attrs',
1313
function (
14-
$scope
14+
$scope, $attrs
1515
) {
16+
$scope.required = typeof $attrs.required !== 'undefined';
1617
$scope.uploadFile = function ($event) {
1718
$scope.fileContainer.file = $event.target.files[0];
1819
};
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/**
2+
* Ushahidi Angular Role Selector directive
3+
* Drop in directive for managing roles addition for users
4+
* and posts
5+
*/
6+
7+
module.exports = [
8+
function (
9+
) {
10+
var controller = [
11+
'$scope',
12+
'$rootScope',
13+
'$translate',
14+
'Notify',
15+
'RoleEndpoint',
16+
'_',
17+
function (
18+
$scope,
19+
$rootScope,
20+
$translate,
21+
Notify,
22+
RoleEndpoint,
23+
_
24+
) {
25+
26+
RoleEndpoint.query().$promise.then(function (roles) {
27+
$scope.roles = roles;
28+
});
29+
30+
$scope.checkIfAllSelected = function () {
31+
return ($scope.roles.length === $scope.post.published_to.length);
32+
};
33+
34+
$scope.toggleRole = function (role) {
35+
if (role === 'draft' || role === '') {
36+
$scope.post.published_to = [];
37+
} else if ($scope.checkIfAllSelected()) {
38+
// All check boxes selected, therefore publish to everyone
39+
$scope.post.published_to = [];
40+
}
41+
42+
$scope.post.status = role === 'draft' ? role : 'published';
43+
44+
$scope.toggleRoleFunc({updatedPost: $scope.post});
45+
};
46+
47+
}];
48+
return {
49+
restrict: 'E',
50+
templateUrl: 'templates/role-selector/role-selector.html',
51+
scope: {
52+
post: '=',
53+
toggleRoleFunc: '&'
54+
},
55+
controller: controller
56+
};
57+
}];

0 commit comments

Comments
 (0)