Skip to content

Commit

Permalink
Merge branch 'develop' - Preparing for v3.2 release
Browse files Browse the repository at this point in the history
  • Loading branch information
rjmackay committed Feb 18, 2016
2 parents 3fb2e11 + 8b902b8 commit 5e1d337
Show file tree
Hide file tree
Showing 153 changed files with 6,195 additions and 743 deletions.
1 change: 1 addition & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"expect",
"inject",
"jasmine",
"fixture",
"spyOn",
"describe",
"beforeEach",
Expand Down
5 changes: 4 additions & 1 deletion app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ var backendUrl = window.ushahidi.backendUrl = window.ushahidi.backendUrl || proc
'config',
'messages',
'notifications',
'contacts'
'contacts',
'roles',
'permissions',
'csv'
];

angular.module('app',
Expand Down
10 changes: 8 additions & 2 deletions app/common/common-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,21 @@ angular.module('ushahidi.common', [

.service('Authentication', require('./services/authentication.js'))
.service('Session', require('./services/session.js'))

.service('ConfigEndpoint', require('./services/endpoints/config.js'))
.service('UserEndpoint', require('./services/endpoints/user-endpoint.js'))
.service('FormEndpoint', require('./services/endpoints/form.js'))
.service('FormAttributeEndpoint', require('./services/endpoints/form-attributes.js'))
.service('FormStageEndpoint', require('./services/endpoints/form-stages.js'))
.service('TagEndpoint', require('./services/endpoints/tag.js'))
.service('RoleEndpoint', require('./services/endpoints/role.js'))
.service('PermissionEndpoint', require('./services/endpoints/permission.js'))
.service('DataProviderEndpoint', require('./services/endpoints/data-providers.js'))
.service('FontAwesomeIcons', require('./services/endpoints/FontAwesomeIcons.js'))
.service('RoleHelper', require('./services/role-helper.js'))

.service('PostViewHelper', require('./services/view-helper.js'))
.service('Config', require('./services/config.js'))
.service('Util', require('./services/util.js'))
.service('DataRetriever', require('./services/data-retriever.js'))
.service('Notify', require('./services/notify.js'))
.service('multiTranslate', require('./services/multi-translate.js'))
.service('GlobalFilter', require('./services/global-filter.js'))
Expand All @@ -33,11 +36,14 @@ angular.module('ushahidi.common', [
.service('Registration', require('./services/registration.js'))
.service('PasswordReset', require('./services/password-reset.js'))
.service('IconManager', require('./services/icon-manager.js'))
.service('FontAwesomeIcons', require('./services/endpoints/FontAwesomeIcons.js'))

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

.directive('collectionSelector', require('./directives/collection-selector.js'))
.directive('roleSelector', require('./directives/role-selector.js'))
.directive('iconPicker', require('./directives/iconpicker.js'))
.directive('firstTimeConfig', require('./directives/first-time-config.js'))

Expand Down
12 changes: 6 additions & 6 deletions app/common/controllers/login-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,30 @@ function (
$scope.$emit('setPageTitle', title);
});

function clearLoginForm() {
$scope.clearLoginForm = function () {
$scope.failed = true;
$scope.processing = false;
$scope.email = '';
$scope.password = '';
}
};

function finishedLogin() {
$scope.finishedLogin = function () {
$scope.failed = false;
$scope.processing = false;
}
};

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

Authentication
.login($scope.email, $scope.password)
.then(finishedLogin, clearLoginForm);
.then($scope.finishedLogin, $scope.clearLoginForm);
};

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

finishedLogin();
$scope.finishedLogin();
}];
15 changes: 12 additions & 3 deletions app/common/controllers/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ function (
// Start with preloaded config
$scope.site = BootstrapConfig;
// Then update from server
var reloadSiteConfig = function () {
$scope.reloadSiteConfig = function () {
ConfigEndpoint.get({ id: 'site' }).$promise.then(function (site) {
$scope.site = site;
});
};

$rootScope.$on('event:update:header', function () {
reloadSiteConfig();
$scope.reloadSiteConfig();
});

$rootScope.$on('$routeChangeSuccess', function (ev, current) {
Expand All @@ -36,7 +36,7 @@ function (
}
});

reloadSiteConfig();
$scope.reloadSiteConfig();

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

$scope.canCreatePost = function () {
return $scope.loggedin || !$scope.site.private;
};

$scope.canRegister = function () {
return !$scope.site.private;
};

$scope.logoutClick = function (e) {
e.preventDefault();
e.stopPropagation();
Authentication.logout();
};



}];
6 changes: 3 additions & 3 deletions app/common/controllers/page-metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ function (
$scope.pageRobots = null;

// Then update from server
var reloadSiteConfig = function () {
$scope.reloadSiteConfig = function () {
ConfigEndpoint.get({ id: 'site' }).$promise.then(function (site) {
$scope.siteTitle = site.name ? site.name : USHAHIDI;
});
};

$rootScope.$on('event:update:header', function () {
reloadSiteConfig();
$scope.reloadSiteConfig();
});
reloadSiteConfig();
$scope.reloadSiteConfig();

$rootScope.$on('setPageTitle', function (event, title) {
$scope.pageTitle = null;
Expand Down
132 changes: 132 additions & 0 deletions app/common/directives/collection-selector.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/**
* Ushahidi Angular Collection Selector directive
* Drop in directive for managing collections addition for posts
*/

module.exports = [
function (
) {
var controller = [
'$scope',
'$rootScope',
'$translate',
'Notify',
'CollectionEndpoint',
'_',
function (
$scope,
$rootScope,
$translate,
Notify,
CollectionEndpoint,
_
) {
$scope.showNewCollectionInput = false;
$scope.newCollection = '';
$scope.editableCollections = [];

$scope.refreshCollections = function () {
CollectionEndpoint.editableByMe().$promise.then(function (results) {
$scope.editableCollections = results;
});
};

$scope.refreshCollections();

$scope.$on('event:collection-selector:update', function () {
$scope.refrehCollections();
});

$scope.postInCollection = function (collection) {
return _.contains($scope.post.sets, String(collection.id));
};

$scope.toggleCreateCollection = function () {
$scope.showNewCollectionInput = !$scope.showNewCollectionInput;
};

$scope.toggleCollection = function (selectedCollection) {
if (_.contains($scope.post.sets, String(selectedCollection.id))) {
$scope.removeFromCollection(selectedCollection);
} else {
$scope.addToCollection(selectedCollection);
}
};

$scope.addToCollection = function (selectedCollection) {
var collectionId = selectedCollection.id, collection = selectedCollection.name;

CollectionEndpoint.addPost({'collectionId': collectionId, 'id': $scope.post.id})
.$promise.then(function () {
$translate('notify.collection.add_to_collection', {collection: collection})
.then(function (message) {
$scope.post.sets.push(String(collectionId));
Notify.showNotificationSlider(message);
});
}, function (errorResponse) {
Notify.showApiErrors(errorResponse);
});
};

$scope.removeFromCollection = function (selectedCollection) {
var collectionId = selectedCollection.id, collection = selectedCollection.name;

CollectionEndpoint.removePost({'collectionId': collectionId, 'id': $scope.post.id})
.$promise
.then(function () {
$translate('notify.collection.removed_from_collection', {collection: collection})
.then(function (message) {
$scope.post.sets = _.without($scope.post.sets, String(collectionId));
Notify.showNotificationSlider(message);
});
}, function (errorResponse) {
Notify.showApiErrors(errorResponse);
});
};
/*
scope.searchCollections = function (query) {
CollectionEndpoint.query(query)
.$promise
.then(function (result) {
}, function (errorResponse) {
Notify.showApiErrors(errorResponse);
});
};
scope.clearSearch = function() {
scope.editableCollection = scope.editableCollectionCopy;
};
*/
$scope.createNewCollection = function (collectionName) {
var collection = {
'name': collectionName,
'user_id': $rootScope.currentUser.userId
};
CollectionEndpoint.save(collection)
.$promise
.then(function (collection) {
$scope.toggleCreateCollection();
$scope.newCollection = '';
$scope.addToCollection(collection);

// Where collection selectors can appear multiple times
// it is necessary to force a collection refresh when an update occurs
// on anyone collection selector - to ensure that newly created collections
// are available in all lists on the page.
// TODO: add caching for collections to reduce requests.
$rootScope.$broadcast('event:collection:update');
}, function (errorResponse) {
Notify.showApiErrors(errorResponse);
});
};

}];
return {
restrict: 'E',
templateUrl: 'templates/collection-selector/collection-selector.html',
scope: {
post: '='
},
controller: controller
};
}];
5 changes: 3 additions & 2 deletions app/common/directives/file-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ angular.module('ushahidi.common.file-upload', [])
},

controller: [
'$scope',
'$scope', '$attrs',
function (
$scope
$scope, $attrs
) {
$scope.required = typeof $attrs.required !== 'undefined';
$scope.uploadFile = function ($event) {
$scope.fileContainer.file = $event.target.files[0];
};
Expand Down
57 changes: 57 additions & 0 deletions app/common/directives/role-selector.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* Ushahidi Angular Role Selector directive
* Drop in directive for managing roles addition for users
* and posts
*/

module.exports = [
function (
) {
var controller = [
'$scope',
'$rootScope',
'$translate',
'Notify',
'RoleEndpoint',
'_',
function (
$scope,
$rootScope,
$translate,
Notify,
RoleEndpoint,
_
) {

RoleEndpoint.query().$promise.then(function (roles) {
$scope.roles = roles;
});

$scope.checkIfAllSelected = function () {
return ($scope.roles.length === $scope.post.published_to.length);
};

$scope.toggleRole = function (role) {
if (role === 'draft' || role === '') {
$scope.post.published_to = [];
} else if ($scope.checkIfAllSelected()) {
// All check boxes selected, therefore publish to everyone
$scope.post.published_to = [];
}

$scope.post.status = role === 'draft' ? role : 'published';

$scope.toggleRoleFunc({updatedPost: $scope.post});
};

}];
return {
restrict: 'E',
templateUrl: 'templates/role-selector/role-selector.html',
scope: {
post: '=',
toggleRoleFunc: '&'
},
controller: controller
};
}];
Loading

0 comments on commit 5e1d337

Please sign in to comment.