Skip to content

Commit

Permalink
merge develop
Browse files Browse the repository at this point in the history
  • Loading branch information
willdoran committed Jun 7, 2016
2 parents 4c96ee6 + 24737f2 commit db072a5
Show file tree
Hide file tree
Showing 229 changed files with 4,347 additions and 3,386 deletions.
5 changes: 4 additions & 1 deletion app/activity/activity-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ angular.module('ushahidi.activity', [])

.config(require('./activity-routes.js'))

.directive('activityTimeline', require('./directives/activity-timeline-directive.js'));
.directive('activityTimeline', require('./activity-timeline.directive.js'))
.directive('activityBarChart', require('./bar-chart.directive.js'))
.directive('activityTimeChart', require('./time-chart.directive.js'))
;
10 changes: 2 additions & 8 deletions app/activity/activity-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,8 @@ function (

$routeProvider
.when('/activity', {
controller: require('./controllers/activity-controller.js'),
templateUrl: 'templates/activity/activity.html',
resolve: {
features: ['Features', function (Features) {
Features.loadFeatures();
return Features;
}]
}
controller: require('./activity.controller.js'),
templateUrl: 'templates/activity/activity.html'
});

}];
File renamed without changes.
81 changes: 81 additions & 0 deletions app/activity/activity.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
module.exports = ActivityController;

ActivityController.$inject = ['$scope', '$translate', 'moment', 'ViewHelper'];

function ActivityController($scope, $translate, moment, ViewHelper) {
// Initial values
$scope.isActivityAvailable = false;
$scope.currentInterval = 'week';
$scope.editableInterval = 'week';
$scope.filters = {
created_after: null,
created_before: null
};
$scope.filtersMenuOpen = false;
$scope.dateOptions = { format : 'yyyy-mm-dd' };

$scope.saveFilters = saveFilters;
$scope.cancelChangeFilters = cancelChangeFilters;

activate();

function activate() {
// Change mode
$scope.$emit('event:mode:change', 'activity');
// Set the page title
$translate('nav.activity').then(function (title) {
$scope.$emit('setPageTitle', title);
});
$scope.isActivityAvailable = ViewHelper.isViewAvailable('activity');

update();
}

function saveFilters() {
$scope.currentInterval = $scope.editableInterval;
update();
$scope.filtersMenuOpen = false;
}

function cancelChangeFilters() {
$scope.editableInterval = $scope.currentInterval;
$scope.filtersMenuOpen = false;
}

function update() {
//$scope.currentInterval = interval;
setDateRange($scope.currentInterval);
}

/**
* Util func to get date range when given an interval like
* @param {String} interval month|week|all
* @return {Object}
*/
function setDateRange(interval) {
switch (interval) {
case 'month':
$scope.filters.created_after = moment().startOf('month').toDate();
$scope.filters.created_before = null;
break;
case 'all':
$scope.filters.created_after = null;
$scope.filters.created_before = null;
break;
case 'custom':
// Do nothing?
$scope.filters.created_after = $scope.createdAfter;
$scope.filters.created_before = $scope.createdBefore;
break;
// case 'week':
default:
// Default to this week
$scope.filters.created_after = moment().startOf('week').toDate();
$scope.filters.created_before = null;
}
// Copy range to editable values
$scope.createdAfter = $scope.filters.created_after;
$scope.createdBefore = $scope.filters.created_before;
return $scope.filters;
}
}
99 changes: 99 additions & 0 deletions app/activity/bar-chart.directive.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
module.exports = ActivityBarChart;

function ActivityBarChart() {
return {
restrict: 'E',
scope: {
filters: '='
},
controller: ActivityBarChartController,
templateUrl: 'templates/activity/bar-chart.html'
};
}

ActivityBarChartController.$inject = ['$scope', '$translate', 'PostEndpoint', 'd3', '_', 'PostFilters'];
function ActivityBarChartController($scope, $translate, PostEndpoint, d3, _, PostFilters) {
$scope.data = [{
values: []
}];

$scope.groupByOptions = {
'tags' : 'nav.categories',
'form' : 'app.surveys',
'status' : 'post.status'
};

$scope.groupBy = {
value: 'tags'
};

$scope.options = {
chart: {
type: 'multiBarHorizontalChart',
height: 450,
margin: {
top: 0,
right: 40,
bottom: 40,
left: 5
},
x: function (d) {
return d.label;
},
y: function (d) {
return d.total;
},
showValues: false,
showControls: false,
valueFormat: d3.format('d'),
transitionDuration: 500,
xAxis: {
axisLabel: $translate.instant('post.categories'),
tickPadding: -10,
axisLabelDistance: 0
},
yAxis: {
axisLabel: $translate.instant('graph.post_count'),
tickFormat: d3.format('d')
},
tooltip : {
contentGenerator: function (data) {
return '<h3>' + data.value + '</h3>' +
'<p>' + data.data.total + '</p>';
}
},
forceY: 0,
barColor: d3.scale.category20().range(),
noData: $translate.instant('graph.no_data')
}
};

$scope.reload = getPostStats;

activate();

function activate() {
// whenever the filters changes, update the current list of posts
$scope.$watch('filters', function () {
getPostStats();
}, true);
}

function getPostStats(query) {
query = query || PostFilters.getQueryParams($scope.filters);
var postQuery = _.extend({}, query, {
'group_by' : $scope.groupBy.value
});

$scope.isLoading = true;
PostEndpoint.stats(postQuery).$promise.then(function (results) {
$scope.options.chart.xAxis.axisLabel = $translate.instant($scope.groupByOptions[$scope.groupBy.value]);
if (results.totals[0]) {
results.totals[0].key = $scope.options.chart.yAxis.axisLabel;
}
$scope.data = results.totals;
$scope.isLoading = false;
});
}

}
191 changes: 0 additions & 191 deletions app/activity/controllers/activity-controller.js

This file was deleted.

0 comments on commit db072a5

Please sign in to comment.