Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 119 additions & 0 deletions www/addons/competency/controllers/competencies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
// (C) Copyright 2015 Martin Dougiamas
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

angular.module('mm.addons.competency')

/**
* Controller to handle competencies of a learning plan.
*
* @module mm.addons.competency
* @ngdoc controller
* @name mmaCompetenciesListCtrl
*/
.controller('mmaCompetenciesListCtrl', function($scope, $mmaCompetency, $mmUtil, $stateParams, $state, $ionicPlatform, $q,
$translate, $mmaCompetencyHelper) {

var planId = parseInt($stateParams.pid) || false,
courseId = parseInt($stateParams.cid) || false,
competencyId = parseInt($stateParams.compid),
userId = parseInt($stateParams.uid) || false;

function fetchCompetencies() {
var promise;

if (planId) {
promise = $mmaCompetency.getLearningPlan(planId);
} else if (courseId){
promise = $mmaCompetency.getCourseCompetencies(courseId);
} else {
promise = $q.reject();
}

return promise.then(function(response) {
if (response.competencycount <= 0) {
return $q.reject($translate.instant('mma.competency.errornocompetenciesfound'));
}

if (planId) {
$scope.title = response.plan.name;
$scope.id = response.plan.id;
$scope.idname = 'planid';
userId = response.plan.userid;
} else {
$scope.title = $translate.instant('mma.competency.coursecompetencies');
$scope.id = response.courseid;
$scope.idname = 'courseid';
}

$scope.competencies = response.competencies;
}).catch(function(message) {
if (message) {
$mmUtil.showErrorModal(message);
} else {
$mmUtil.showErrorModal('Error getting competencies data.');
}
return $q.reject();
});
}

$scope.gotoCompetency = function(competencyId) {
if (planId) {
// Show split view on tablet.
$state.go('site.competency', {planid: planId, competencyid: competencyId});
} else {
$state.go('site.competency', {courseid: courseId, competencyid: competencyId, userid: userId});
}
};

// Convenience function to refresh all the data.
function refreshAllData() {
var promise;
if (planId) {
promise = $mmaCompetency.invalidateLearningPlan(planId);
} else {
promise = $mmaCompetency.invalidateCourseCompetencies(courseId);
}
return promise.finally(function() {
return fetchCompetencies();
});
}

// Convenience function to autoload a competency if competencyId param is set.
function autoloadCompetency() {
if (competencyId) {
if ($ionicPlatform.isTablet()) {
// Search the position of the section to load.
angular.forEach($scope.competencies, function(competency, index) {
if (competency.competency.id == competencyId) {
$scope.competencyToLoad = index + 1;
}
});
} else {
$scope.gotoCompetency(competencyId);
}
}
}

fetchCompetencies().finally(function() {
autoloadCompetency();
$scope.competenciesLoaded = true;
});

// Pull to refresh.
$scope.refreshCompetencies = function() {
refreshAllData().finally(function() {
$scope.$broadcast('scroll.refreshComplete');
});
};
});
132 changes: 132 additions & 0 deletions www/addons/competency/controllers/competency.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
// (C) Copyright 2015 Martin Dougiamas
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

angular.module('mm.addons.competency')

/**
* Controller to handle a competency in plan.
*
* @module mm.addons.competency
* @ngdoc controller
* @name mmaCompetencyCtrl
*/
.controller('mmaCompetencyCtrl', function($scope, $stateParams, $mmaCompetency, $mmUtil, $translate, $q, $mmSite,
mmaCompetencyReviewStatusIdle, mmaCompetencyReviewStatusInReview, mmaCompetencyReviewStatusWaitingForReview) {

var competencyId = parseInt($stateParams.competencyid),
planId = parseInt($stateParams.planid) || false,
courseId = parseInt($stateParams.courseid) || false,
userId = parseInt($stateParams.userid) || false,
planStatus = false;

// Convenience function that fetches the event and updates the scope.
function fetchCompetency() {

if (planId) {
planStatus = false;
promise = $mmaCompetency.getCompetencyInPlan(planId, competencyId);
} else if (courseId){
promise = $mmaCompetency.getCompetencyInCourse(courseId, competencyId, userId);
} else {
promise = $q.reject();
}

return promise.then(function(competency) {

if (planId) {
planStatus = competency.plan.status;
competency.usercompetencysummary.usercompetency.statusname = getStatusName(competency.usercompetencysummary.usercompetency.status);
} else {
competency.usercompetencysummary.usercompetency = competency.usercompetencysummary.usercompetencycourse;
$scope.coursemodules = competency.coursemodules;
}

if (competency.usercompetencysummary.user.id != $mmSite.getUserId()) {
competency.usercompetencysummary.user.profileimageurl = competency.usercompetencysummary.user.profileimageurl
|| true;

// Get the user profile image from the returned object.
$scope.user = competency.usercompetencysummary.user;
console.log($scope.user);
}

angular.forEach(competency.usercompetencysummary.evidence, function(evidence) {
if (evidence.descidentifier) {
evidence.description = $translate.instant('mma.competency.' + evidence.descidentifier, {a: evidence.desca});
}
});

$scope.competency = competency.usercompetencysummary;

}, function(message) {
if (message) {
$mmUtil.showErrorModal(message);
} else {
$mmUtil.showErrorModal('Error getting competency data.');
}
return $q.reject();
});
}

// Convenience function to get the review status name translated
function getStatusName(status) {
var statusTranslateName;
switch (status) {
case mmaCompetencyReviewStatusIdle:
statusTranslateName = 'idle';
break;
case mmaCompetencyReviewStatusInReview:
statusTranslateName = 'inreview';
break;
case mmaCompetencyReviewStatusWaitingForReview:
statusTranslateName = 'waitingforreview';
break;
default:
// We can use the current status name.
return status;
}
return $translate.instant('mma.competency.usercompetencystatus_' + statusTranslateName);
}

// Convenience function to refresh all the data.
function refreshAllData() {
var promise;

if (planId) {
promise = $mmaCompetency.invalidateCompetencyInPlan(planId, competencyId);
} else {
promise = $mmaCompetency.invalidateCompetencyInCourse(courseId, competencyId);
}
return promise.finally(function() {
return fetchCompetency();
});
}

fetchCompetency().then(function() {
if (planId) {
$mmaCompetency.logCompetencyInPlanView(planId, competencyId, planStatus, userId);
} else {
$mmaCompetency.logCompetencyInCourseView(courseId, competencyId, userId);
}
}).finally(function() {
$scope.competencyLoaded = true;
});

// Pull to refresh.
$scope.refreshCompetency = function() {
refreshAllData().finally(function() {
$scope.$broadcast('scroll.refreshComplete');
});
};
});
61 changes: 61 additions & 0 deletions www/addons/competency/controllers/competencysummary.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// (C) Copyright 2015 Martin Dougiamas
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

angular.module('mm.addons.competency')

/**
* Controller to handle a competency summary.
*
* @module mm.addons.competency
* @ngdoc controller
* @name mmaCompetencySummaryCtrl
*/
.controller('mmaCompetencySummaryCtrl', function($scope, $stateParams, $mmaCompetency, $mmUtil, $q) {

var competencyId = parseInt($stateParams.competencyid);

// Convenience function that fetches the event and updates the scope.
function fetchCompetency() {
return $mmaCompetency.getCompetencySummary(competencyId).then(function(competency) {
$scope.competency = competency;
}, function(message) {
if (message) {
$mmUtil.showErrorModal(message);
} else {
$mmUtil.showErrorModal('Error getting competency summary data.');
}
return $q.reject();
});
}

// Convenience function to refresh all the data.
function refreshAllData() {
return $mmaCompetency.invalidateCompetencySummary(competencyId).finally(function() {
return fetchCompetency();
});
}

fetchCompetency().then(function() {
$mmaCompetency.logCompetencyView(competencyId);
}).finally(function() {
$scope.competencyLoaded = true;
});

// Pull to refresh.
$scope.refreshCompetency = function() {
refreshAllData().finally(function() {
$scope.$broadcast('scroll.refreshComplete');
});
};
});
75 changes: 75 additions & 0 deletions www/addons/competency/controllers/coursecompetencies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// (C) Copyright 2015 Martin Dougiamas
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

angular.module('mm.addons.competency')

/**
* Controller to handle course competencies.
*
* @module mm.addons.competency
* @ngdoc controller
* @name mmaCourseCompetenciesCtrl
*/
.controller('mmaCourseCompetenciesCtrl', function($scope, $stateParams, $mmaCompetency, $mmUtil, $state, $ionicPlatform, $q,
$mmaCompetencyHelper) {

var courseId = parseInt($stateParams.courseid);
userId = parseInt($stateParams.userid) || false;

// Convenience function that fetches the event and updates the scope.
function fetchCourseCompetencies() {
return $mmaCompetency.getCourseCompetencies(courseId).then(function(competencies) {
$scope.competencies = competencies;

// Get the user profile image.
$mmaCompetencyHelper.getProfile(userId).then(function(user) {
$scope.user = user;
});
}, function(message) {
if (message) {
$mmUtil.showErrorModal(message);
} else {
$mmUtil.showErrorModal('Error getting course competencies data.');
}
return $q.reject();
});
}

$scope.gotoCompetency = function(competencyId) {
if ($ionicPlatform.isTablet()) {
// Show split view on tablet.
$state.go('site.competencies', {cid: courseId, compid: competencyId, uid: userId});
} else {
$state.go('site.competency', {courseid: courseId, competencyid: competencyId, userid: userId});
}
};

// Convenience function to refresh all the data.
function refreshAllData() {
return $mmaCompetency.invalidateCourseCompetencies(courseId).finally(function() {
return fetchCourseCompetencies();
});
}

fetchCourseCompetencies().finally(function() {
$scope.competenciesLoaded = true;
});

// Pull to refresh.
$scope.refreshCourseCompetencies = function() {
refreshAllData().finally(function() {
$scope.$broadcast('scroll.refreshComplete');
});
};
});
Loading