diff --git a/src/addon/mod/choice/components/index/addon-mod-choice-index.html b/src/addon/mod/choice/components/index/addon-mod-choice-index.html index dda24a3bf..a0c95cbe7 100644 --- a/src/addon/mod/choice/components/index/addon-mod-choice-index.html +++ b/src/addon/mod/choice/components/index/addon-mod-choice-index.html @@ -61,35 +61,37 @@ - +
{{ 'addon.mod_choice.responses' | translate }} - + {{ 'addon.mod_choice.resultsnotsynced' | translate }} - + - - -

-

{{ 'addon.mod_choice.numberofuser' | translate }}: {{ result.numberofuser }} ({{ 'core.percentagenumber' | translate: {$a: result.percentageamount} }})

- + + + +

+

{{ 'addon.mod_choice.numberofuser' | translate }}: {{ result.numberofuser }} ({{ 'core.percentagenumber' | translate: {$a: result.percentageamount} }})

+
+

{{user.fullname}}

-
+
- +

{{ 'addon.mod_choice.noresultsviewable' | translate }}

diff --git a/src/addon/mod/feedback/components/index/addon-mod-feedback-index.html b/src/addon/mod/feedback/components/index/addon-mod-feedback-index.html index 2d6339728..544ba8255 100644 --- a/src/addon/mod/feedback/components/index/addon-mod-feedback-index.html +++ b/src/addon/mod/feedback/components/index/addon-mod-feedback-index.html @@ -163,7 +163,7 @@ - +

{{ 'addon.mod_feedback.average' | translate }}: {{item.average | number : '1.2-2'}}

diff --git a/src/app/app.scss b/src/app/app.scss index 739bb6134..9eb4390d6 100644 --- a/src/app/app.scss +++ b/src/app/app.scss @@ -681,11 +681,6 @@ textarea { height: auto; } -canvas[core-chart] { - max-width: 500px; - margin: 0 auto; -} - .core-circle:before { content: ' \25CF'; } diff --git a/src/components/chart/chart.scss b/src/components/chart/chart.scss new file mode 100644 index 000000000..0194f1f9b --- /dev/null +++ b/src/components/chart/chart.scss @@ -0,0 +1,8 @@ +core-chart { + display: block; + + canvas { + max-width: 500px; + margin: 0 auto; + } +} \ No newline at end of file diff --git a/src/directives/chart.ts b/src/components/chart/chart.ts similarity index 83% rename from src/directives/chart.ts rename to src/components/chart/chart.ts index 3da2dd1ad..55ec191ca 100644 --- a/src/directives/chart.ts +++ b/src/components/chart/chart.ts @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { Directive, Input, OnDestroy, OnInit, ElementRef, OnChanges } from '@angular/core'; +import { Component, Input, OnDestroy, OnInit, ElementRef, OnChanges, ViewChild } from '@angular/core'; import { Chart } from 'chart.js'; /** @@ -21,12 +21,13 @@ import { Chart } from 'chart.js'; * It only supports changes on these properties: data and labels. * * Example usage: - * + * */ -@Directive({ - selector: 'canvas[core-chart]' +@Component({ + selector: 'core-chart', + templateUrl: 'core-chart.html' }) -export class CoreChartDirective implements OnDestroy, OnInit, OnChanges { +export class CoreChartComponent implements OnDestroy, OnInit, OnChanges { // The first 6 colors will be the app colors, the following will be randomly generated. // It will use the same colors in the whole session. protected static backgroundColors = [ @@ -42,12 +43,13 @@ export class CoreChartDirective implements OnDestroy, OnInit, OnChanges { @Input() labels = []; // Labels of the data. @Input() type: string; // Type of chart. @Input() legend: any; // Legend options. + @Input() height = 300; // Height of the chart element. + @ViewChild('canvas') canvas: ElementRef; chart: any; - protected element: ElementRef; - constructor(element: ElementRef) { - this.element = element; + constructor() { + // Nothing to do. } /** @@ -57,8 +59,7 @@ export class CoreChartDirective implements OnDestroy, OnInit, OnChanges { let legend = {}; if (typeof this.legend == 'undefined') { legend = { - display: true, - position: 'bottom', + display: false, labels: { generateLabels: (chart): any => { const data = chart.data; @@ -85,7 +86,7 @@ export class CoreChartDirective implements OnDestroy, OnInit, OnChanges { this.type = 'horizontalBar'; } - const context = this.element.nativeElement.getContext('2d'); + const context = this.canvas.nativeElement.getContext('2d'); this.chart = new Chart(context, { type: this.type, data: { @@ -120,14 +121,14 @@ export class CoreChartDirective implements OnDestroy, OnInit, OnChanges { * @return {any[]} Array with the number of background colors requested. */ protected getRandomColors(n: number): any[] { - while (CoreChartDirective.backgroundColors.length < n) { + while (CoreChartComponent.backgroundColors.length < n) { const red = Math.floor(Math.random() * 255), green = Math.floor(Math.random() * 255), blue = Math.floor(Math.random() * 255); - CoreChartDirective.backgroundColors.push('rgba(' + red + ', ' + green + ', ' + blue + ', 0.6)'); + CoreChartComponent.backgroundColors.push('rgba(' + red + ', ' + green + ', ' + blue + ', 0.6)'); } - return CoreChartDirective.backgroundColors.slice(0, n); + return CoreChartComponent.backgroundColors.slice(0, n); } /** diff --git a/src/components/chart/core-chart.html b/src/components/chart/core-chart.html new file mode 100644 index 000000000..c4adca0b8 --- /dev/null +++ b/src/components/chart/core-chart.html @@ -0,0 +1,8 @@ + + + + + + {{data.text}} + + diff --git a/src/components/components.module.ts b/src/components/components.module.ts index e6ff951c4..6163a7d83 100644 --- a/src/components/components.module.ts +++ b/src/components/components.module.ts @@ -32,6 +32,7 @@ import { CoreContextMenuComponent } from './context-menu/context-menu'; import { CoreContextMenuItemComponent } from './context-menu/context-menu-item'; import { CoreContextMenuPopoverComponent } from './context-menu/context-menu-popover'; import { CoreCoursePickerMenuPopoverComponent } from './course-picker-menu/course-picker-menu-popover'; +import { CoreChartComponent } from './chart/chart'; import { CoreChronoComponent } from './chrono/chrono'; import { CoreLocalFileComponent } from './local-file/local-file'; import { CoreSitePickerComponent } from './site-picker/site-picker'; @@ -66,6 +67,7 @@ import { CoreIonTabComponent } from './ion-tabs/ion-tab'; CoreContextMenuItemComponent, CoreContextMenuPopoverComponent, CoreCoursePickerMenuPopoverComponent, + CoreChartComponent, CoreChronoComponent, CoreLocalFileComponent, CoreSitePickerComponent, @@ -108,6 +110,7 @@ import { CoreIonTabComponent } from './ion-tabs/ion-tab'; CoreIconComponent, CoreContextMenuComponent, CoreContextMenuItemComponent, + CoreChartComponent, CoreChronoComponent, CoreLocalFileComponent, CoreSitePickerComponent, diff --git a/src/directives/directives.module.ts b/src/directives/directives.module.ts index 90c21ca2e..e3ad9693b 100644 --- a/src/directives/directives.module.ts +++ b/src/directives/directives.module.ts @@ -22,7 +22,6 @@ import { CoreKeepKeyboardDirective } from './keep-keyboard'; import { CoreUserLinkDirective } from './user-link'; import { CoreAutoRowsDirective } from './auto-rows'; import { CoreLongPressDirective } from './long-press'; -import { CoreChartDirective } from './chart'; import { CoreBackButtonDirective } from './back-button'; import { CoreSupressEventsDirective } from './supress-events'; @@ -37,7 +36,6 @@ import { CoreSupressEventsDirective } from './supress-events'; CoreUserLinkDirective, CoreAutoRowsDirective, CoreLongPressDirective, - CoreChartDirective, CoreBackButtonDirective, CoreSupressEventsDirective ], @@ -52,7 +50,6 @@ import { CoreSupressEventsDirective } from './supress-events'; CoreUserLinkDirective, CoreAutoRowsDirective, CoreLongPressDirective, - CoreChartDirective, CoreBackButtonDirective, CoreSupressEventsDirective ] diff --git a/upgrade.txt b/upgrade.txt new file mode 100644 index 000000000..9696b88f7 --- /dev/null +++ b/upgrade.txt @@ -0,0 +1,6 @@ +This files describes API changes in the Moodle Mobile app, +information provided here is intended especially for developers. + +=== 3.5.2 === + +- CoreChartDirective changed from directive to component (CoreChartComponent) and the selector to use it changed from canvas[core-chart] to core-chart.