Skip to content

Commit 927fb29

Browse files
committed
MOBILE-1547 cbe: Add learning plans support
1 parent 31f092b commit 927fb29

File tree

17 files changed

+1736
-0
lines changed

17 files changed

+1736
-0
lines changed
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
// (C) Copyright 2015 Martin Dougiamas
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
angular.module('mm.addons.competency')
16+
17+
/**
18+
* Controller to handle competencies of a learning plan.
19+
*
20+
* @module mm.addons.competency
21+
* @ngdoc controller
22+
* @name mmaCompetenciesListCtrl
23+
*/
24+
.controller('mmaCompetenciesListCtrl', function($scope, $log, $mmaCompetency, $mmUtil, $stateParams, $state, $ionicPlatform, $q,
25+
$translate) {
26+
27+
$log = $log.getInstance('mmaCompetenciesListCtrl');
28+
29+
var planId = parseInt($stateParams.pid) || false,
30+
courseId = parseInt($stateParams.cid) || false,
31+
competencyId = parseInt($stateParams.compid);
32+
33+
function fetchCompetencies(refresh) {
34+
var promise;
35+
36+
if (planId) {
37+
promise = $mmaCompetency.getLearningPlan(planId);
38+
} else if (courseId){
39+
promise = $mmaCompetency.getCourseCompetencies(courseId);
40+
} else {
41+
promise = $q.reject();
42+
}
43+
44+
return promise.then(function(response) {
45+
if (response.competencycount <= 0) {
46+
return $q.reject($translate.instant('mma.competency.errornocompetenciesfound'));
47+
}
48+
49+
if (planId) {
50+
$scope.title = response.plan.name;
51+
$scope.id = response.plan.id;
52+
$scope.idname = 'planid';
53+
} else {
54+
$scope.title = $translate.instant('mma.competency.coursecompetencies');
55+
$scope.id = response.courseid;
56+
$scope.idname = 'courseid';
57+
}
58+
59+
$scope.competencies = response.competencies;
60+
}).catch(function(message) {
61+
if (!refresh) {
62+
// Some call failed, retry without using cache.
63+
return refreshAllData();
64+
}
65+
66+
if (message) {
67+
$mmUtil.showErrorModal(message);
68+
} else {
69+
$mmUtil.showErrorModal('Error getting competencies data.');
70+
}
71+
return $q.reject();
72+
});
73+
}
74+
75+
$scope.gotoCompetency = function(competencyId) {
76+
if (planId) {
77+
// Show split view on tablet.
78+
$state.go('site.competency', {planid: planId, competencyid: competencyId});
79+
} else {
80+
$state.go('site.competency', {courseid: courseId, competencyid: competencyId});
81+
}
82+
};
83+
84+
// Convenience function to refresh all the data.
85+
function refreshAllData() {
86+
var promise;
87+
if (planId) {
88+
promise = $mmaCompetency.invalidateLearningPlan(planId);
89+
} else {
90+
promise = $mmaCompetency.invalidateCourseCompetencies(courseId);
91+
}
92+
return promise.finally(function() {
93+
return fetchCompetencies(true);
94+
});
95+
}
96+
97+
// Convenience function to autoload a competency if competencyId param is set.
98+
function autoloadCompetency() {
99+
if (competencyId) {
100+
if ($ionicPlatform.isTablet()) {
101+
// Search the position of the section to load.
102+
angular.forEach($scope.competencies, function(competency, index) {
103+
if (competency.competency.id == competencyId) {
104+
$scope.competencyToLoad = index + 1;
105+
}
106+
});
107+
} else {
108+
$scope.gotoCompetency(competencyId);
109+
}
110+
}
111+
}
112+
113+
fetchCompetencies().finally(function() {
114+
autoloadCompetency();
115+
$scope.competenciesLoaded = true;
116+
});
117+
118+
// Pull to refresh.
119+
$scope.refreshCompetencies = function() {
120+
refreshAllData().finally(function() {
121+
$scope.$broadcast('scroll.refreshComplete');
122+
});
123+
};
124+
});
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
// (C) Copyright 2015 Martin Dougiamas
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
angular.module('mm.addons.competency')
16+
17+
/**
18+
* Controller to handle a competency in plan.
19+
*
20+
* @module mm.addons.competency
21+
* @ngdoc controller
22+
* @name Competency
23+
*/
24+
.controller('mmaCompetencyCtrl', function($scope, $log, $stateParams, $mmaCompetency, $mmUtil, $translate, $q,
25+
mmaCompetencyReviewStatusIdle, mmaCompetencyReviewStatusInReview, mmaCompetencyReviewStatusWaitingForReview) {
26+
27+
$log = $log.getInstance('mmaCompetencyCtrl');
28+
29+
var competencyId = parseInt($stateParams.competencyid),
30+
planId = parseInt($stateParams.planid) || false,
31+
courseId = parseInt($stateParams.courseid) || false;
32+
33+
// Convenience function that fetches the event and updates the scope.
34+
function fetchCompetency(refresh) {
35+
36+
if (planId) {
37+
promise = $mmaCompetency.getCompetencyInPlan(planId, competencyId);
38+
} else if (courseId){
39+
promise = $mmaCompetency.getCompetencyInCourse(courseId, competencyId);
40+
} else {
41+
promise = $q.reject();
42+
}
43+
44+
return promise.then(function(competency) {
45+
46+
if (planId) {
47+
statusName = getStatusName(competency.usercompetencysummary.usercompetency.status);
48+
if (statusName) {
49+
competency.usercompetencysummary.usercompetency.statusname = statusName;
50+
}
51+
} else {
52+
competency.usercompetencysummary.usercompetency = competency.usercompetencysummary.usercompetencycourse;
53+
$scope.coursemodules = competency.coursemodules;
54+
}
55+
56+
angular.forEach(competency.usercompetencysummary.evidence, function(evidence) {
57+
if (evidence.descidentifier) {
58+
evidence.description = $translate.instant('mma.competency.' + evidence.descidentifier, {a: evidence.desca});
59+
}
60+
});
61+
62+
$scope.competency = competency.usercompetencysummary;
63+
64+
}, function(message) {
65+
if (!refresh) {
66+
// Some call failed, retry without using cache.
67+
return refreshAllData();
68+
}
69+
70+
if (message) {
71+
$mmUtil.showErrorModal(message);
72+
} else {
73+
$mmUtil.showErrorModal('Error getting competency data.');
74+
}
75+
return $q.reject();
76+
});
77+
}
78+
79+
// Convenience function to get the review status name translated
80+
function getStatusName(status) {
81+
var statusTranslateName;
82+
switch (status) {
83+
case mmaCompetencyReviewStatusIdle:
84+
statusTranslateName = 'idle';
85+
break;
86+
case mmaCompetencyReviewStatusInReview:
87+
statusTranslateName = 'inreview';
88+
break;
89+
case mmaCompetencyReviewStatusWaitingForReview:
90+
statusTranslateName = 'waitingforreview';
91+
break;
92+
default:
93+
// We can use the current status name.
94+
return false;
95+
}
96+
return $translate.instant('mma.competency.usercompetencystatus_' + statusTranslateName);
97+
}
98+
99+
// Convenience function to refresh all the data.
100+
function refreshAllData() {
101+
var promise;
102+
103+
if (planId) {
104+
promise = $mmaCompetency.invalidateCompetencyInPlan(planId, competencyId);
105+
} else {
106+
promise = $mmaCompetency.invalidateCompetencyInCourse(courseId, competencyId);
107+
}
108+
return promise.finally(function() {
109+
return fetchCompetency(true);
110+
});
111+
}
112+
113+
// Get event.
114+
fetchCompetency().finally(function() {
115+
if (planId) {
116+
$mmaCompetency.logCompetencyInPlanView(planId, competencyId);
117+
} else {
118+
$mmaCompetency.logCompetencyInCourseView(courseId, competencyId);
119+
}
120+
}).finally(function() {
121+
$scope.competencyLoaded = true;
122+
});
123+
124+
// Pull to refresh.
125+
$scope.refreshCompetency = function() {
126+
fetchCompetency(true).finally(function() {
127+
$scope.$broadcast('scroll.refreshComplete');
128+
});
129+
};
130+
});
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// (C) Copyright 2015 Martin Dougiamas
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
angular.module('mm.addons.competency')
16+
17+
/**
18+
* Controller to handle a competency summary.
19+
*
20+
* @module mm.addons.competency
21+
* @ngdoc controller
22+
* @name Competency
23+
*/
24+
.controller('mmaCompetencySummaryCtrl', function($scope, $log, $stateParams, $mmaCompetency, $mmUtil, $q) {
25+
26+
$log = $log.getInstance('mmaCompetencySummaryCtrl');
27+
28+
var competencyId = parseInt($stateParams.competencyid);
29+
30+
// Convenience function that fetches the event and updates the scope.
31+
function fetchCompetency(refresh) {
32+
return $mmaCompetency.getCompetencySummary(competencyId).then(function(competency) {
33+
$scope.competency = competency;
34+
}, function(message) {
35+
if (!refresh) {
36+
// Some call failed, retry without using cache.
37+
return refreshAllData();
38+
}
39+
40+
if (message) {
41+
$mmUtil.showErrorModal(message);
42+
} else {
43+
$mmUtil.showErrorModal('Error getting competency summary data.');
44+
}
45+
return $q.reject();
46+
});
47+
}
48+
49+
// Convenience function to refresh all the data.
50+
function refreshAllData() {
51+
return $mmaCompetency.invalidateCompetencySummary(competencyId).finally(function() {
52+
return fetchCompetency(true);
53+
});
54+
}
55+
56+
// Get event.
57+
fetchCompetency().finally(function() {
58+
$mmaCompetency.logCompetencyView(competencyId);
59+
}).finally(function() {
60+
$scope.competencyLoaded = true;
61+
});
62+
63+
// Pull to refresh.
64+
$scope.refreshCompetency = function() {
65+
fetchCompetency(true).finally(function() {
66+
$scope.$broadcast('scroll.refreshComplete');
67+
});
68+
};
69+
});

0 commit comments

Comments
 (0)