MOBILE-2338 data: Add actions

main
Pau Ferrer Ocaña 2018-05-08 15:10:32 +02:00
parent 661dbe2260
commit 44e8acbb5e
6 changed files with 156 additions and 8 deletions

View File

@ -0,0 +1,34 @@
<a *ngIf="action == 'more'" ion-button icon-only clear [href]="url" core-link capture-link="true" [title]="'addon.mod_data.more' | translate">
<ion-icon name="search"></ion-icon>
</a>
<a *ngIf="action == 'edit'" ion-button icon-only clear [href]="url" core-link capture-link="true" [title]="'core.edit' | translate">
<ion-icon name="cog"></ion-icon>
</a>
<a *ngIf="action == 'delete' && !entry.deleted" ion-button icon-only clear [href]="url" core-link capture-link="true" [title]="'core.delete' | translate">
<ion-icon name="trash"></ion-icon>
</a>
<a *ngIf="action == 'delete' && entry.deleted" ion-button icon-only clear (click)="undoDelete()" [title]="'core.restore' | translate">
<ion-icon name="undo"></ion-icon>
</a>
<a *ngIf="action == 'approve'" ion-button icon-only clear [href]="url" core-link capture-link="true" [title]="'addon.mod_data.approve' | translate">
<ion-icon name="thumbs-up"></ion-icon>
</a>
<a *ngIf="action == 'disapprove'" ion-button icon-only clear [href]="url" core-link capture-link="true" [title]="'addon.mod_data.disapprove' | translate">
<ion-icon name="thumbs-down"></ion-icon>
</a>
<core-comments *ngIf="action == 'comments' && mode == 'list'" contextLevel="module" [instanceId]="database.coursemodule" component="mod_data" [itemId]="entry.id" area="database_entry"></core-comments>
<span *ngIf="action == 'timeadded'">{{ entry.timecreated * 1000 | coreFormatDate:"dffulldate" }}</span>
<span *ngIf="action == 'timemodified'">{{ entry.timemodified * 1000 | coreFormatDate:"dffulldate" }}</span>
<a *ngIf="action == 'userpicture'" core-user-link [courseId]="database.courseid" [userId]="entry.userid" [title]="entry.fullname">
<img class="avatar-round" [src]="userPicture" [alt]="'core.pictureof' | translate:{$a: user.fullname}" core-external-content onError="this.src='assets/img/user-avatar.png'" role="presentation">
</a>
<a *ngIf="action == 'user'" core-user-link [courseId]="database.courseid" [userId]="entry.userid" [title]="entry.fullname">{{entry.fullname}}</a>

View File

@ -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<any>} Solved when done.
*/
undoDelete(): Promise<any> {
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;
}
}
}

View File

@ -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

View File

@ -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',

View File

@ -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 = '<addon-mod-data-action action="' + action + '" entry="entries[' + entry.id +
']" mode="' + mode + '" database="data"></addon-mod-data-action>';
render = '<addon-mod-data-action action="' + action + '" [entry]="entries[' + entry.id +
']" mode="' + mode + '" [database]="data"></addon-mod-data-action>';
}
template = template.replace(replace, render);
} else {
template = template.replace(replace, '');
}
}*/
}
return template;
}

View File

@ -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<any>} Promise resolved with entry.
*/
getEntry(dataId: number, entryId: number, action: string, siteId?: string): Promise<any> {
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.
*