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
73 changes: 64 additions & 9 deletions www/addons/mod/data/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ angular.module('mm.addons.mod_data')
* @name mmaModDataIndexCtrl
*/
.controller('mmaModDataIndexCtrl', function($scope, $stateParams, $mmaModData, mmaModDataComponent, $mmCourse, $mmCourseHelper, $q,
$mmText, $translate, $mmEvents, mmCoreEventOnlineStatusChanged, $mmApp, $mmUtil, $mmSite) {
$mmText, $translate, $mmEvents, mmCoreEventOnlineStatusChanged, $mmApp, $mmUtil, $mmSite, $mmaModDataHelper, $mmGroups) {

var module = $stateParams.module || {},
courseId = $stateParams.courseid,
Expand All @@ -33,13 +33,12 @@ angular.module('mm.addons.mod_data')
$scope.description = module.description;
$scope.moduleUrl = module.url;
$scope.moduleName = $mmCourse.translateModuleName('data');
$scope.courseId = courseId;
$scope.refreshIcon = 'spinner';
$scope.syncIcon = 'spinner';
$scope.component = mmaModDataComponent;
$scope.componentId = module.id;
$scope.databaseLoaded = false;

$scope.selectedGroup = $stateParams.group || 0;

function fetchDatabaseData(refresh, sync, showErrors) {
$scope.isOnline = $mmApp.isOnline();
Expand All @@ -49,10 +48,12 @@ angular.module('mm.addons.mod_data')

$scope.title = data.name || $scope.title;
$scope.description = data.intro || $scope.description;
$scope.data = databaseData;

$scope.database = data;

return $mmaModData.getDatabaseAccessInformation(data.id);

}).then(function(accessData) {
$scope.access = accessData;

Expand All @@ -66,13 +67,31 @@ angular.module('mm.addons.mod_data')
$scope.timeAvailableTo = data.timeavailableto && time > data.timeavailableto ?
parseInt(data.timeavailableto, 10) * 1000 : false;
$scope.timeAvailableToReadable = $scope.timeAvailableTo ? moment($scope.timeAvailableTo).format('LLL') : false;
} else {
// TODO: Calculate num entries based on get_entries WS.
$scope.numEntries = accessData.numentries;
$scope.entriesLeftToView = accessData.entrieslefttoview;
$scope.entriesLeftToAdd = accessData.entrieslefttoadd;
$scope.canAdd = accessData.canaddentry;

$scope.isEmpty = true;
$scope.groupInfo = false;
return false;
}

return $mmGroups.getActivityGroupInfo(data.coursemodule, accessData.canmanageentries).then(function(groupInfo) {
$scope.groupInfo = groupInfo;

// Check selected group is accessible.
if (groupInfo && groupInfo.groups && groupInfo.groups.length > 0) {
var found = false;
for (var x in groupInfo.groups) {
if (groupInfo.groups[x].id == $scope.selectedGroup) {
found = true;
break;
}
}
if (!found) {
$scope.selectedGroup = groupInfo.groups[0].id;
}
}

return fetchEntriesData();
});
}).then(function() {
// All data obtained, now fill the context menu.
$mmCourseHelper.fillContextMenu($scope, module, courseId, refresh, mmaModDataComponent);
Expand All @@ -89,10 +108,46 @@ angular.module('mm.addons.mod_data')
});
}

function fetchEntriesData() {
return $mmaModData.getDatabaseAccessInformation(data.id, $scope.selectedGroup).then(function(accessData) {
// Update values for current group.
$scope.access.canaddentry = accessData.canaddentry;

return $mmaModData.getEntries(data.id, $scope.selectedGroup).then(function(entries) {
$scope.isEmpty = !entries || entries.entries.length <= 0;
$scope.entries = "";

if (!$scope.isEmpty) {
$scope.cssTemplate = $mmaModDataHelper.prefixCSS(data.csstemplate, '.mma-data-entries-' + data.id);
$scope.entries = entries.listviewcontents;
}
});
});
}


// Set group to see the database.
$scope.setGroup = function(groupId) {
$scope.selectedGroup = groupId;
return fetchEntriesData().catch(function(message) {
$mmUtil.showErrorModalDefault(message, 'mm.course.errorgetmodule', true);
return $q.reject();
});
};



// Convenience function to refresh all the data.
function refreshAllData(sync, showErrors) {
var promises = [];

promises.push($mmaModData.invalidateDatabaseData(courseId));
if (data) {
promises.push($mmaModData.invalidateDatabaseAccessInformationData(data.id));
promises.push($mmGroups.invalidateActivityGroupInfo(data.coursemodule));
promises.push($mmaModData.invalidateEntriesData(data.id));
}

return $q.all(promises).finally(function() {
return fetchDatabaseData(true, sync, showErrors);
});
Expand Down
8 changes: 5 additions & 3 deletions www/addons/mod/data/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ angular.module('mm.addons.mod_data', ['mm.core'])
url: '/mod_data',
params: {
module: null,
courseid: null
courseid: null,
group: null
},
views: {
'site': {
Expand All @@ -36,7 +37,8 @@ angular.module('mm.addons.mod_data', ['mm.core'])

})

.config(function($mmCourseDelegateProvider, $mmContentLinksDelegateProvider) {
.config(function($mmCourseDelegateProvider, $mmContentLinksDelegateProvider, $mmCoursePrefetchDelegateProvider) {
$mmCourseDelegateProvider.registerContentHandler('mmaModData', 'data', '$mmaModDataHandlers.courseContent');
$mmContentLinksDelegateProvider.registerLinkHandler('mmaModData', '$mmaModDataHandlers.linksHandler');
$mmCoursePrefetchDelegateProvider.registerPrefetchHandler('mmaModData', 'data', '$mmaModDataPrefetchHandler');
$mmContentLinksDelegateProvider.registerLinkHandler('mmaModData:index', '$mmaModDataHandlers.indexLinksHandler');
});
18 changes: 18 additions & 0 deletions www/addons/mod/data/scss/styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

.mm-site_mod_data {
.recordcheckbox {
display: none;
}
}

.mm-data-contents {
overflow: visible;
white-space: normal;
word-break: break-all;
padding: $item-padding;
background-color: white;
border-top-width: $item-border-width;
border-bottom-width: $item-border-width;
border-style: solid;
border-color: $item-default-border;
}
Loading