Skip to content

Commit 9f51098

Browse files
committed
Merge pull request #485 from crazyserver/MOBILE-1547
Mobile 1547
2 parents f0da432 + 3550901 commit 9f51098

File tree

20 files changed

+1925
-2
lines changed

20 files changed

+1925
-2
lines changed
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
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, $mmaCompetency, $mmUtil, $stateParams, $state, $ionicPlatform, $q,
25+
$translate, $mmaCompetencyHelper) {
26+
27+
var planId = parseInt($stateParams.pid) || false,
28+
courseId = parseInt($stateParams.cid) || false,
29+
competencyId = parseInt($stateParams.compid),
30+
userId = parseInt($stateParams.uid) || false;
31+
32+
function fetchCompetencies() {
33+
var promise;
34+
35+
if (planId) {
36+
promise = $mmaCompetency.getLearningPlan(planId);
37+
} else if (courseId){
38+
promise = $mmaCompetency.getCourseCompetencies(courseId);
39+
} else {
40+
promise = $q.reject();
41+
}
42+
43+
return promise.then(function(response) {
44+
if (response.competencycount <= 0) {
45+
return $q.reject($translate.instant('mma.competency.errornocompetenciesfound'));
46+
}
47+
48+
if (planId) {
49+
$scope.title = response.plan.name;
50+
$scope.id = response.plan.id;
51+
$scope.idname = 'planid';
52+
userId = response.plan.userid;
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 (message) {
62+
$mmUtil.showErrorModal(message);
63+
} else {
64+
$mmUtil.showErrorModal('Error getting competencies data.');
65+
}
66+
return $q.reject();
67+
});
68+
}
69+
70+
$scope.gotoCompetency = function(competencyId) {
71+
if (planId) {
72+
// Show split view on tablet.
73+
$state.go('site.competency', {planid: planId, competencyid: competencyId});
74+
} else {
75+
$state.go('site.competency', {courseid: courseId, competencyid: competencyId, userid: userId});
76+
}
77+
};
78+
79+
// Convenience function to refresh all the data.
80+
function refreshAllData() {
81+
var promise;
82+
if (planId) {
83+
promise = $mmaCompetency.invalidateLearningPlan(planId);
84+
} else {
85+
promise = $mmaCompetency.invalidateCourseCompetencies(courseId);
86+
}
87+
return promise.finally(function() {
88+
return fetchCompetencies();
89+
});
90+
}
91+
92+
// Convenience function to autoload a competency if competencyId param is set.
93+
function autoloadCompetency() {
94+
if (competencyId) {
95+
if ($ionicPlatform.isTablet()) {
96+
// Search the position of the section to load.
97+
angular.forEach($scope.competencies, function(competency, index) {
98+
if (competency.competency.id == competencyId) {
99+
$scope.competencyToLoad = index + 1;
100+
}
101+
});
102+
} else {
103+
$scope.gotoCompetency(competencyId);
104+
}
105+
}
106+
}
107+
108+
fetchCompetencies().finally(function() {
109+
autoloadCompetency();
110+
$scope.competenciesLoaded = true;
111+
});
112+
113+
// Pull to refresh.
114+
$scope.refreshCompetencies = function() {
115+
refreshAllData().finally(function() {
116+
$scope.$broadcast('scroll.refreshComplete');
117+
});
118+
};
119+
});
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
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 mmaCompetencyCtrl
23+
*/
24+
.controller('mmaCompetencyCtrl', function($scope, $stateParams, $mmaCompetency, $mmUtil, $translate, $q, $mmSite,
25+
mmaCompetencyReviewStatusIdle, mmaCompetencyReviewStatusInReview, mmaCompetencyReviewStatusWaitingForReview) {
26+
27+
var competencyId = parseInt($stateParams.competencyid),
28+
planId = parseInt($stateParams.planid) || false,
29+
courseId = parseInt($stateParams.courseid) || false,
30+
userId = parseInt($stateParams.userid) || false,
31+
planStatus = false;
32+
33+
// Convenience function that fetches the event and updates the scope.
34+
function fetchCompetency() {
35+
36+
if (planId) {
37+
planStatus = false;
38+
promise = $mmaCompetency.getCompetencyInPlan(planId, competencyId);
39+
} else if (courseId){
40+
promise = $mmaCompetency.getCompetencyInCourse(courseId, competencyId, userId);
41+
} else {
42+
promise = $q.reject();
43+
}
44+
45+
return promise.then(function(competency) {
46+
47+
if (planId) {
48+
planStatus = competency.plan.status;
49+
competency.usercompetencysummary.usercompetency.statusname = getStatusName(competency.usercompetencysummary.usercompetency.status);
50+
} else {
51+
competency.usercompetencysummary.usercompetency = competency.usercompetencysummary.usercompetencycourse;
52+
$scope.coursemodules = competency.coursemodules;
53+
}
54+
55+
if (competency.usercompetencysummary.user.id != $mmSite.getUserId()) {
56+
competency.usercompetencysummary.user.profileimageurl = competency.usercompetencysummary.user.profileimageurl
57+
|| true;
58+
59+
// Get the user profile image from the returned object.
60+
$scope.user = competency.usercompetencysummary.user;
61+
console.log($scope.user);
62+
}
63+
64+
angular.forEach(competency.usercompetencysummary.evidence, function(evidence) {
65+
if (evidence.descidentifier) {
66+
evidence.description = $translate.instant('mma.competency.' + evidence.descidentifier, {a: evidence.desca});
67+
}
68+
});
69+
70+
$scope.competency = competency.usercompetencysummary;
71+
72+
}, function(message) {
73+
if (message) {
74+
$mmUtil.showErrorModal(message);
75+
} else {
76+
$mmUtil.showErrorModal('Error getting competency data.');
77+
}
78+
return $q.reject();
79+
});
80+
}
81+
82+
// Convenience function to get the review status name translated
83+
function getStatusName(status) {
84+
var statusTranslateName;
85+
switch (status) {
86+
case mmaCompetencyReviewStatusIdle:
87+
statusTranslateName = 'idle';
88+
break;
89+
case mmaCompetencyReviewStatusInReview:
90+
statusTranslateName = 'inreview';
91+
break;
92+
case mmaCompetencyReviewStatusWaitingForReview:
93+
statusTranslateName = 'waitingforreview';
94+
break;
95+
default:
96+
// We can use the current status name.
97+
return status;
98+
}
99+
return $translate.instant('mma.competency.usercompetencystatus_' + statusTranslateName);
100+
}
101+
102+
// Convenience function to refresh all the data.
103+
function refreshAllData() {
104+
var promise;
105+
106+
if (planId) {
107+
promise = $mmaCompetency.invalidateCompetencyInPlan(planId, competencyId);
108+
} else {
109+
promise = $mmaCompetency.invalidateCompetencyInCourse(courseId, competencyId);
110+
}
111+
return promise.finally(function() {
112+
return fetchCompetency();
113+
});
114+
}
115+
116+
fetchCompetency().then(function() {
117+
if (planId) {
118+
$mmaCompetency.logCompetencyInPlanView(planId, competencyId, planStatus, userId);
119+
} else {
120+
$mmaCompetency.logCompetencyInCourseView(courseId, competencyId, userId);
121+
}
122+
}).finally(function() {
123+
$scope.competencyLoaded = true;
124+
});
125+
126+
// Pull to refresh.
127+
$scope.refreshCompetency = function() {
128+
refreshAllData().finally(function() {
129+
$scope.$broadcast('scroll.refreshComplete');
130+
});
131+
};
132+
});
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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 mmaCompetencySummaryCtrl
23+
*/
24+
.controller('mmaCompetencySummaryCtrl', function($scope, $stateParams, $mmaCompetency, $mmUtil, $q) {
25+
26+
var competencyId = parseInt($stateParams.competencyid);
27+
28+
// Convenience function that fetches the event and updates the scope.
29+
function fetchCompetency() {
30+
return $mmaCompetency.getCompetencySummary(competencyId).then(function(competency) {
31+
$scope.competency = competency;
32+
}, function(message) {
33+
if (message) {
34+
$mmUtil.showErrorModal(message);
35+
} else {
36+
$mmUtil.showErrorModal('Error getting competency summary data.');
37+
}
38+
return $q.reject();
39+
});
40+
}
41+
42+
// Convenience function to refresh all the data.
43+
function refreshAllData() {
44+
return $mmaCompetency.invalidateCompetencySummary(competencyId).finally(function() {
45+
return fetchCompetency();
46+
});
47+
}
48+
49+
fetchCompetency().then(function() {
50+
$mmaCompetency.logCompetencyView(competencyId);
51+
}).finally(function() {
52+
$scope.competencyLoaded = true;
53+
});
54+
55+
// Pull to refresh.
56+
$scope.refreshCompetency = function() {
57+
refreshAllData().finally(function() {
58+
$scope.$broadcast('scroll.refreshComplete');
59+
});
60+
};
61+
});
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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 course competencies.
19+
*
20+
* @module mm.addons.competency
21+
* @ngdoc controller
22+
* @name mmaCourseCompetenciesCtrl
23+
*/
24+
.controller('mmaCourseCompetenciesCtrl', function($scope, $stateParams, $mmaCompetency, $mmUtil, $state, $ionicPlatform, $q,
25+
$mmaCompetencyHelper) {
26+
27+
var courseId = parseInt($stateParams.courseid);
28+
userId = parseInt($stateParams.userid) || false;
29+
30+
// Convenience function that fetches the event and updates the scope.
31+
function fetchCourseCompetencies() {
32+
return $mmaCompetency.getCourseCompetencies(courseId).then(function(competencies) {
33+
$scope.competencies = competencies;
34+
35+
// Get the user profile image.
36+
$mmaCompetencyHelper.getProfile(userId).then(function(user) {
37+
$scope.user = user;
38+
});
39+
}, function(message) {
40+
if (message) {
41+
$mmUtil.showErrorModal(message);
42+
} else {
43+
$mmUtil.showErrorModal('Error getting course competencies data.');
44+
}
45+
return $q.reject();
46+
});
47+
}
48+
49+
$scope.gotoCompetency = function(competencyId) {
50+
if ($ionicPlatform.isTablet()) {
51+
// Show split view on tablet.
52+
$state.go('site.competencies', {cid: courseId, compid: competencyId, uid: userId});
53+
} else {
54+
$state.go('site.competency', {courseid: courseId, competencyid: competencyId, userid: userId});
55+
}
56+
};
57+
58+
// Convenience function to refresh all the data.
59+
function refreshAllData() {
60+
return $mmaCompetency.invalidateCourseCompetencies(courseId).finally(function() {
61+
return fetchCourseCompetencies();
62+
});
63+
}
64+
65+
fetchCourseCompetencies().finally(function() {
66+
$scope.competenciesLoaded = true;
67+
});
68+
69+
// Pull to refresh.
70+
$scope.refreshCourseCompetencies = function() {
71+
refreshAllData().finally(function() {
72+
$scope.$broadcast('scroll.refreshComplete');
73+
});
74+
};
75+
});

0 commit comments

Comments
 (0)