From aef3f535282bd330bd19faada50f2849c0c1ecbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Mon, 4 Jun 2018 12:14:46 +0200 Subject: [PATCH] MOBILE-2354 workshop: Assessment component --- .../components/assessment/assessment.html | 27 ++++ .../components/assessment/assessment.scss | 35 ++++ .../components/assessment/assessment.ts | 149 ++++++++++++++++++ .../workshop/components/components.module.ts | 7 +- .../workshop/pages/submission/submission.html | 8 +- .../workshop/pages/submission/submission.ts | 2 +- src/addon/mod/workshop/workshop.scss | 5 +- 7 files changed, 225 insertions(+), 8 deletions(-) create mode 100644 src/addon/mod/workshop/components/assessment/assessment.html create mode 100644 src/addon/mod/workshop/components/assessment/assessment.scss create mode 100644 src/addon/mod/workshop/components/assessment/assessment.ts diff --git a/src/addon/mod/workshop/components/assessment/assessment.html b/src/addon/mod/workshop/components/assessment/assessment.html new file mode 100644 index 000000000..d277f8eb7 --- /dev/null +++ b/src/addon/mod/workshop/components/assessment/assessment.html @@ -0,0 +1,27 @@ + + + + + + +

{{profile.fullname}}

+

+ {{ 'addon.mod_workshop.submissiongradeof' | translate:{$a: workshop.grade } }}: {{assessment.grade}} +

+

+ {{ 'addon.mod_workshop.gradinggradeof' | translate:{$a: workshop.gradinggrade } }}: {{assessment.gradinggrade}} +

+

+ {{ 'addon.mod_workshop.gradinggradeof' | translate:{$a: workshop.gradinggrade } }}: {{assessment.gradinggradeover}} +

+

+ {{ 'addon.mod_workshop.weightinfo' | translate:{$a: assessment.weight } }} +

+ {{ 'addon.mod_workshop.notassessed' | translate }} + + + + {{ 'core.notsent' | translate }} + +
+
diff --git a/src/addon/mod/workshop/components/assessment/assessment.scss b/src/addon/mod/workshop/components/assessment/assessment.scss new file mode 100644 index 000000000..9ed4dbcc5 --- /dev/null +++ b/src/addon/mod/workshop/components/assessment/assessment.scss @@ -0,0 +1,35 @@ +addon-mod-workshop-assessment { + .item-md.item-block .item-inner { + border-bottom: 1px solid $list-md-border-color; + } + + .item-ios.item-block .item-inner { + border-bottom: $hairlines-width solid $list-ios-border-color; + } + + .item-wp.item-block .item-inner { + border-bottom: 1px solid $list-wp-border-color; + } + + &:last-child .item .item-inner { + border-bottom: 0; + } +} + +.card.with-borders addon-mod-workshop-assessment { + .item-md.item-block .item-inner { + border-bottom: 1px solid $list-md-border-color; + } + + .item-ios.item-block .item-inner { + border-bottom: $hairlines-width solid $list-ios-border-color; + } + + .item-wp.item-block .item-inner { + border-bottom: 1px solid $list-wp-border-color; + } + + &:last-child .item .item-inner { + border-bottom: 0; + } +} \ No newline at end of file diff --git a/src/addon/mod/workshop/components/assessment/assessment.ts b/src/addon/mod/workshop/components/assessment/assessment.ts new file mode 100644 index 000000000..7e16f1491 --- /dev/null +++ b/src/addon/mod/workshop/components/assessment/assessment.ts @@ -0,0 +1,149 @@ +// (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 } from '@angular/core'; +import { NavController } from 'ionic-angular'; +import { CoreSitesProvider } from '@providers/sites'; +import { CoreUserProvider } from '@core/user/providers/user'; +import { CoreDomUtilsProvider } from '@providers/utils/dom'; +import { AddonModWorkshopHelperProvider } from '../../providers/helper'; +import { AddonModWorkshopOfflineProvider } from '../../providers/offline'; + +/** + * Component that displays workshop assessment. + */ +@Component({ + selector: 'addon-mod-workshop-assessment', + templateUrl: 'assessment.html', +}) +export class AddonModWorkshopAssessmentComponent implements OnInit { + @Input() assessment: any; + @Input() summary?: boolean; + @Input() courseId: number; + @Input() submission: any; + @Input() module?: any; + @Input() workshop: any; + @Input() access: any; + + canViewAssessment = false; + canSelfAssess = false; + profile: any; + showGrade: any; + offline = false; + loaded = false; + + protected currentUserId: number; + protected assessmentId: number; + + constructor(private workshopOffline: AddonModWorkshopOfflineProvider, private workshopHelper: AddonModWorkshopHelperProvider, + private navCtrl: NavController, private userProvider: CoreUserProvider, private domUtils: CoreDomUtilsProvider, + sitesProvider: CoreSitesProvider) { + this.currentUserId = sitesProvider.getCurrentSiteUserId(); + this.showGrade = this.workshopHelper.showGrade; + } + + /** + * Component being initialized. + */ + ngOnInit(): void { + const canAssess = this.access && this.access.assessingallowed, + userId = this.assessment.userid || this.assessment.reviewerid, + promises = []; + + this.assessmentId = this.assessment.assessmentid || this.assessment.id; + this.canViewAssessment = this.assessment.grade; + this.canSelfAssess = canAssess && userId == this.currentUserId; + + if (userId) { + promises.push(this.userProvider.getProfile(userId, this.courseId, true).then((profile) => { + this.profile = profile; + })); + } + + let assessOffline; + if (userId == this.currentUserId) { + assessOffline = this.workshopOffline.getAssessment(this.workshop.id, this.assessmentId) .then((offlineAssess) => { + this.offline = true; + this.assessment.weight = offlineAssess.inputdata.weight; + }); + } else { + assessOffline = this.workshopOffline.getEvaluateAssessment(this.workshop.id, this.assessmentId) + .then((offlineAssess) => { + this.offline = true; + this.assessment.gradinggradeover = offlineAssess.gradinggradeover; + this.assessment.weight = offlineAssess.weight; + }); + } + + promises.push(assessOffline.catch(() => { + this.offline = false; + // Ignore errors. + })); + + Promise.all(promises).finally(() => { + this.loaded = true; + }); + } + + /** + * Navigate to the assessment. + */ + gotoAssessment(): void { + if (!this.canSelfAssess && this.canViewAssessment) { + const params = { + assessment: this.assessment, + submission: this.submission, + profile: this.profile, + courseId: this.courseId, + assessmentId: this.assessmentId + }; + + if (!this.submission) { + const modal = this.domUtils.showModalLoading('core.sending', true); + + this.workshopHelper.getSubmissionById(this.workshop.id, this.assessment.submissionid) + .then((submissionData) => { + + params.submission = submissionData; + this.navCtrl.push('AddonModWorkshopAssessmentPage', params); + }).catch((message) => { + this.domUtils.showErrorModalDefault(message, 'Cannot load submission'); + }).finally(() => { + modal.dismiss(); + }); + } else { + this.navCtrl.push('AddonModWorkshopAssessmentPage', params); + } + } + } + + /** + * Navigate to my own assessment. + */ + gotoOwnAssessment(): void { + if (this.canSelfAssess) { + const params = { + module: this.module, + workshop: this.workshop, + access: this.access, + courseId: this.courseId, + profile: this.profile, + submission: this.submission, + assessment: this.assessment + }; + + this.navCtrl.push('AddonModWorkshopSubmissionPage', params); + } + } +} diff --git a/src/addon/mod/workshop/components/components.module.ts b/src/addon/mod/workshop/components/components.module.ts index cdcf3f5e6..0c1e07224 100644 --- a/src/addon/mod/workshop/components/components.module.ts +++ b/src/addon/mod/workshop/components/components.module.ts @@ -22,11 +22,13 @@ import { CorePipesModule } from '@pipes/pipes.module'; import { CoreCourseComponentsModule } from '@core/course/components/components.module'; import { AddonModWorkshopIndexComponent } from './index/index'; import { AddonModWorkshopSubmissionComponent } from './submission/submission'; +import { AddonModWorkshopAssessmentComponent } from './assessment/assessment'; @NgModule({ declarations: [ AddonModWorkshopIndexComponent, - AddonModWorkshopSubmissionComponent + AddonModWorkshopSubmissionComponent, + AddonModWorkshopAssessmentComponent ], imports: [ CommonModule, @@ -41,7 +43,8 @@ import { AddonModWorkshopSubmissionComponent } from './submission/submission'; ], exports: [ AddonModWorkshopIndexComponent, - AddonModWorkshopSubmissionComponent + AddonModWorkshopSubmissionComponent, + AddonModWorkshopAssessmentComponent ], entryComponents: [ AddonModWorkshopIndexComponent diff --git a/src/addon/mod/workshop/pages/submission/submission.html b/src/addon/mod/workshop/pages/submission/submission.html index d77cd6d4a..851a1e531 100644 --- a/src/addon/mod/workshop/pages/submission/submission.html +++ b/src/addon/mod/workshop/pages/submission/submission.html @@ -48,21 +48,23 @@

{{ 'addon.mod_workshop.yourassessment' | translate }}

- +

{{ 'addon.mod_workshop.receivedgrades' | translate }}

- + + +

{{ 'addon.mod_workshop.givengrades' | translate }}

- +
diff --git a/src/addon/mod/workshop/pages/submission/submission.ts b/src/addon/mod/workshop/pages/submission/submission.ts index 4a6ba7235..7d8e30cf6 100644 --- a/src/addon/mod/workshop/pages/submission/submission.ts +++ b/src/addon/mod/workshop/pages/submission/submission.ts @@ -36,7 +36,7 @@ import { AddonModWorkshopSyncProvider } from '../../providers/sync'; */ @IonicPage({ segment: 'addon-mod-workshop-submission' }) @Component({ - selector: 'page-addon-mod-workshop-submission', + selector: 'page-addon-mod-workshop-submission-page', templateUrl: 'submission.html', }) export class AddonModWorkshopSubmissionPage implements OnInit, OnDestroy { diff --git a/src/addon/mod/workshop/workshop.scss b/src/addon/mod/workshop/workshop.scss index 3f79267f3..ab0146f9c 100644 --- a/src/addon/mod/workshop/workshop.scss +++ b/src/addon/mod/workshop/workshop.scss @@ -1,6 +1,7 @@ addon-mod-workshop-submission, -addon-mod-workshop-assessment, // TODO, change names -addon-mod-workshop-assessment { +addon-mod-workshop-submission-page, +addon-mod-workshop-assessment, +addon-mod-workshop-assessment-page { p.addon-overriden-grade { color: color($colors, success);