diff --git a/src/addon/mod/data/components/action/action.html b/src/addon/mod/data/components/action/action.html new file mode 100644 index 000000000..9588699a2 --- /dev/null +++ b/src/addon/mod/data/components/action/action.html @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + +{{ entry.timecreated * 1000 | coreFormatDate:"dffulldate" }} +{{ entry.timemodified * 1000 | coreFormatDate:"dffulldate" }} + + + + + +{{entry.fullname}} diff --git a/src/addon/mod/data/components/action/action.ts b/src/addon/mod/data/components/action/action.ts new file mode 100644 index 000000000..0cdb76f45 --- /dev/null +++ b/src/addon/mod/data/components/action/action.ts @@ -0,0 +1,92 @@ +// (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. +import { Component, Input, OnInit, Injector } from '@angular/core'; +import { CoreEventsProvider } from '@providers/events'; +import { AddonModDataProvider } from '../../providers/data'; +import { AddonModDataOfflineProvider } from '../../providers/offline'; +import { CoreSitesProvider } from '@providers/sites'; +import { CoreUserProvider } from '@core/user/providers/user'; + +/** + * Component that displays a database action. + */ +@Component({ + selector: 'addon-mod-data-action', + templateUrl: 'action.html', +}) +export class AddonModDataActionComponent implements OnInit { + @Input() mode: string; // The render mode. + @Input() action: string; // The field to render. + @Input() entry?: any; // The value of the field. + @Input() database: any; // Database object. + + siteId: string; + rootUrl: string; + url: string; + userPicture: string; + + constructor(protected injector: Injector, protected dataProvider: AddonModDataProvider, + protected dataOffline: AddonModDataOfflineProvider, protected eventsProvider: CoreEventsProvider, + sitesProvider: CoreSitesProvider, protected userProvider: CoreUserProvider) { + this.rootUrl = sitesProvider.getCurrentSite().getURL(); + this.siteId = sitesProvider.getCurrentSiteId(); + } + + /** + * Undo delete action. + * + * @return {Promise} Solved when done. + */ + undoDelete(): Promise { + const dataId = this.database.id, + entryId = this.entry.id; + + return this.dataOffline.getEntry(dataId, entryId, 'delete', this.siteId).then(() => { + // Found. Just delete the action. + return this.dataOffline.deleteEntry(dataId, entryId, 'delete', this.siteId); + }).then(() => { + this.eventsProvider.trigger(AddonModDataProvider.ENTRY_CHANGED, {dataId: dataId, entryId: entryId}, this.siteId); + }); + } + + /** + * Component being initialized. + */ + ngOnInit(): void { + switch (this.action) { + case 'more': + this.url = this.rootUrl + '/mod/data/view.php?d= ' + this.entry.dataid + '&rid=' + this.entry.id; + break; + case 'edit': + this.url = this.rootUrl + '/mod/data/edit.php?d= ' + this.entry.dataid + '&rid=' + this.entry.id; + break; + case 'delete': + this.url = this.rootUrl + '/mod/data/view.php?d= ' + this.entry.dataid + '&delete=' + this.entry.id; + break; + case 'approve': + this.url = this.rootUrl + '/mod/data/view.php?d= ' + this.entry.dataid + '&approve=' + this.entry.id; + break; + case 'disapprove': + this.url = this.rootUrl + '/mod/data/view.php?d= ' + this.entry.dataid + '&disapprove=' + this.entry.id; + break; + case 'userpicture': + this.userProvider.getProfile(this.entry.userid, this.database.courseid).then((profile) => { + this.userPicture = profile.profileimageurl; + }); + break; + default: + break; + } + } +} diff --git a/src/addon/mod/data/components/components.module.ts b/src/addon/mod/data/components/components.module.ts index 7b979b396..3470ae872 100644 --- a/src/addon/mod/data/components/components.module.ts +++ b/src/addon/mod/data/components/components.module.ts @@ -18,15 +18,19 @@ import { IonicModule } from 'ionic-angular'; import { TranslateModule } from '@ngx-translate/core'; import { CoreComponentsModule } from '@components/components.module'; import { CoreDirectivesModule } from '@directives/directives.module'; +import { CorePipesModule } from '@pipes/pipes.module'; import { CoreCourseComponentsModule } from '@core/course/components/components.module'; import { AddonModDataIndexComponent } from './index/index'; import { AddonModDataFieldPluginComponent } from './field-plugin/field-plugin'; +import { AddonModDataActionComponent } from './action/action'; import { CoreCompileHtmlComponentModule } from '@core/compile/components/compile-html/compile-html.module'; +import { CoreCommentsComponentsModule } from '@core/comments/components/components.module'; @NgModule({ declarations: [ AddonModDataIndexComponent, - AddonModDataFieldPluginComponent + AddonModDataFieldPluginComponent, + AddonModDataActionComponent ], imports: [ CommonModule, @@ -34,14 +38,17 @@ import { CoreCompileHtmlComponentModule } from '@core/compile/components/compile TranslateModule.forChild(), CoreComponentsModule, CoreDirectivesModule, + CorePipesModule, CoreCourseComponentsModule, - CoreCompileHtmlComponentModule + CoreCompileHtmlComponentModule, + CoreCommentsComponentsModule ], providers: [ ], exports: [ AddonModDataIndexComponent, - AddonModDataFieldPluginComponent + AddonModDataFieldPluginComponent, + AddonModDataActionComponent ], entryComponents: [ AddonModDataIndexComponent diff --git a/src/addon/mod/data/components/field-plugin/field-plugin.ts b/src/addon/mod/data/components/field-plugin/field-plugin.ts index cbac94fa2..8fcf975f0 100644 --- a/src/addon/mod/data/components/field-plugin/field-plugin.ts +++ b/src/addon/mod/data/components/field-plugin/field-plugin.ts @@ -17,7 +17,7 @@ import { AddonModDataFieldsDelegate } from '../../providers/fields-delegate'; import { CoreDynamicComponent } from '@components/dynamic-component/dynamic-component'; /** - * Component that displays an assignment feedback plugin. + * Component that displays a database field plugin. */ @Component({ selector: 'addon-mod-data-field-plugin', diff --git a/src/addon/mod/data/providers/helper.ts b/src/addon/mod/data/providers/helper.ts index 8f929e8b0..52e90e251 100644 --- a/src/addon/mod/data/providers/helper.ts +++ b/src/addon/mod/data/providers/helper.ts @@ -162,7 +162,7 @@ export class AddonModDataHelperProvider { template = template.replace(replace, render); }); - /*for (const action in actions) { + for (const action in actions) { replace = new RegExp('##' + action + '##', 'gi'); // Is enabled? if (actions[action]) { @@ -172,14 +172,14 @@ export class AddonModDataHelperProvider { } else if (action == 'approvalstatus') { render = this.translate.instant('addon.mod_data.' + (entry.approved ? 'approved' : 'notapproved')); } else { - render = ''; + render = ''; } template = template.replace(replace, render); } else { template = template.replace(replace, ''); } - }*/ + } return template; } diff --git a/src/addon/mod/data/providers/offline.ts b/src/addon/mod/data/providers/offline.ts index a4f01382b..03cff2081 100644 --- a/src/addon/mod/data/providers/offline.ts +++ b/src/addon/mod/data/providers/offline.ts @@ -131,6 +131,21 @@ export class AddonModDataOfflineProvider { }); } + /** + * Get an stored entry data. + * + * @param {number} dataId Database ID. + * @param {number} entryId Database entry Id. + * @param {string} action Action to be done + * @param {string} [siteId] Site ID. If not defined, current site. + * @return {Promise} Promise resolved with entry. + */ + getEntry(dataId: number, entryId: number, action: string, siteId?: string): Promise { + return this.sitesProvider.getSite(siteId).then((site) => { + return site.getDb().getRecord(this.SURVEY_TABLE, {dataid: dataId, entryid: entryId, action: action}); + }); + } + /** * Get an all stored entry actions data. *