Skip to content

Commit

Permalink
feat(*): event/note details can now be exported individually (#1186)
Browse files Browse the repository at this point in the history
closes #1160

Co-authored-by: Simon <therealslimv@yahoo.de>
  • Loading branch information
sleidig and TheSlimvReal authored Apr 8, 2022
1 parent 5a8b315 commit fbfc016
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,37 @@
<h1>{{ entity.date | date }}: {{ entity.subject }}</h1>

<form #entityForm="ngForm" class="form-wrapper">
<div class="additional-actions-menu">
<button
mat-icon-button
[matMenuTriggerFor]="additional"
color="primary"
>
<fa-icon icon="ellipsis-v" class="standard-icon"></fa-icon>
</button>
<mat-menu
#additional
>
<button
mat-menu-item
[appExportData]="[entity]"
format="csv"
[exportConfig]="exportConfig"
[filename]="'event_' + entity.subject.replace(' ', '-') + '_' + (entity.date | date:'YYYY-MM-dd')"
>
<fa-icon
class="standard-icon"
aria-label="download csv"
icon="download"
angulartics2On="click"
angularticsCategory="Note"
angularticsAction="single_note_csv_export"
></fa-icon>
<span i18n="Download note details as CSV"> Download details </span>
</button>
</mat-menu>
</div>

<!-- General context of Note -->
<div class="content-header">
<mat-form-field>
Expand Down Expand Up @@ -125,7 +156,7 @@ <h1>{{ entity.date | date }}: {{ entity.subject }}</h1>
[(selection)]="entity.children"
(selectionChange)="entityForm.form.markAsDirty()"
[additionalFilter]="filterInactiveChildren"
[showEntities]="!isMeeting"
[showEntities]="!entity.category?.isMeeting"
label="Participants"
i18n-label="Participants of a note"
placeholder="Add participant ..."
Expand All @@ -143,7 +174,7 @@ <h1>{{ entity.date | date }}: {{ entity.subject }}</h1>
</mat-option>
</app-entity-select>

<div *ngIf="isMeeting">
<div *ngIf="entity.category?.isMeeting">
<app-child-meeting-note-attendance
*ngFor="let childId of entity.children"
[childId]="childId"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,9 @@
gap: $standard-margin-small;
padding: $standard-margin-small;
}

.additional-actions-menu {
position: absolute;
right: 8px;
top: 16px;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import { INTERACTION_TYPE_CONFIG_ID } from "../model/interaction-type.interface"
import { Child } from "../../children/model/child";
import { User } from "../../../core/user/user";
import { School } from "../../schools/model/school";
import { ExportColumnConfig } from "../../../core/export/export-service/export-column-config";
import { ConfigService } from "../../../core/config/config.service";
import { EntityListConfig } from "../../../core/entity-components/entity-list/EntityListConfig";

/**
* Component responsible for displaying the Note creation/view window
Expand All @@ -26,6 +29,15 @@ export class NoteDetailsComponent implements ShowsEntity<Note> {
readonly INTERACTION_TYPE_CONFIG = INTERACTION_TYPE_CONFIG_ID;
includeInactiveChildren: boolean = false;

/** export format for notes to be used for downloading the individual details */
exportConfig: ExportColumnConfig[];

constructor(private configService: ConfigService) {
this.exportConfig = this.configService.getConfig<{
config: EntityListConfig;
}>("view:note").config.exportConfig;
}

toggleIncludeInactiveChildren() {
this.includeInactiveChildren = !this.includeInactiveChildren;
// This needs to be set so that the filtering will start immediately
Expand All @@ -35,8 +47,4 @@ export class NoteDetailsComponent implements ShowsEntity<Note> {
}

filterInactiveChildren: (Child) => boolean = (c: Child) => c.isActive;

get isMeeting(): boolean {
return this.entity.category?.isMeeting || false;
}
}
2 changes: 2 additions & 0 deletions src/app/child-dev-project/notes/notes.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { FontAwesomeModule } from "@fortawesome/angular-fontawesome";
import { NotesDashboardComponent } from "./dashboard-widgets/notes-dashboard/notes-dashboard.component";
import { NotesOfChildComponent } from "./notes-of-child/notes-of-child.component";
import { DashboardModule } from "../../core/dashboard/dashboard.module";
import { ExportModule } from "../../core/export/export.module";

@NgModule({
declarations: [
Expand Down Expand Up @@ -103,6 +104,7 @@ import { DashboardModule } from "../../core/dashboard/dashboard.module";
FontAwesomeModule,
MatMenuModule,
DashboardModule,
ExportModule,
],
exports: [NoteDetailsComponent],
})
Expand Down
33 changes: 4 additions & 29 deletions src/app/core/export/export-service/export.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,7 @@ describe("ExportService", () => {
const columnValues = rows[1].split(ExportService.SEPARATOR_COL);
expect(columnValues).toHaveSize(3 + 1); // Properties + _id
expect(columnValues).toContain('"' + testEnumValue.label + '"');
expect(columnValues).toContain(
'"' + moment(new Date(testDate)).toISOString(true) + '"'
);
expect(columnValues).toContain('"' + testDate + '"');
expect(columnValues).toContain('"true"');
});

Expand Down Expand Up @@ -277,11 +275,10 @@ describe("ExportService", () => {
]);
});

it("should export a date according to the local format", async () => {
// Create date at midnight on first of january 2021
it("should export a date as YYYY-MM-dd only", async () => {
const dateString = "2021-01-01";
const dateObject = new Date(dateString);
dateObject.setHours(0, 0, 0);
dateObject.setHours(10, 11, 12);

const exportData = [
{
Expand All @@ -294,12 +291,9 @@ describe("ExportService", () => {
const csv = await service.createCsv(exportData);

const results = csv.split(ExportService.SEPARATOR_ROW);
// Format: yyyy-mm-ddThh:mm:ss.mmm+hh:mm
const expectedDateFormat =
dateString + "T00:00:00.000" + getTimezoneOffset(dateObject);
expect(results).toEqual([
'"date","number","string"',
`"${expectedDateFormat}","10","someString"`,
`"${dateString}","10","someString"`,
]);
});

Expand Down Expand Up @@ -529,23 +523,4 @@ describe("ExportService", () => {

return school;
}

/**
* Returns the timezone offset in hours and minutes.
* E.g. german date object => "+02:00" or "+01:00" depending on time of the year
* @param date object for which the offset should be calculated
*/
function getTimezoneOffset(date: Date): string {
// from https://usefulangle.com/post/30/javascript-get-date-time-with-offset-hours-minutes
const offset = date.getTimezoneOffset();

const offsetHrs = parseInt(Math.abs(offset / 60).toString(), 10);
const offsetMin = Math.abs(offset % 60);

const hrsString = offsetHrs > 10 ? offsetHrs.toString() : "0" + offsetHrs;
const minString = offsetMin > 10 ? offsetMin.toString() : "0" + offsetMin;

const sign = offset > 0 ? "-" : "+";
return sign + hrsString + ":" + minString;
}
});
5 changes: 3 additions & 2 deletions src/app/core/export/export-service/export.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,9 @@ export class ExportService {
const readableRow = {};
Object.keys(row).forEach((key) => {
if (row[key] instanceof Date) {
// Export data according to local timezone offset
readableRow[key] = moment(row[key]).toISOString(true);
// Export data according to local timezone offset - data is loaded through Entity Schema system and thereby has the correct date in the current device's timezone
// TODO: make this output format configurable or use the different date schema types [GITHUB #1185]
readableRow[key] = moment(row[key]).format("YYYY-MM-DD");
} else {
readableRow[key] = getReadableValue(row, key);
}
Expand Down
31 changes: 20 additions & 11 deletions src/locale/messages.de.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
<note priority="1" from="description">Groups that belong to a note</note>
<context-group purpose="location">
<context context-type="sourcefile">src/app/child-dev-project/notes/note-details/note-details.component.html</context>
<context context-type="linenumber">162</context>
<context context-type="linenumber">193</context>
</context-group>
</trans-unit>
<trans-unit id="d3233bd79e5ab0f7f5e9600bb5b8ef470bdb4bc6" datatype="html">
Expand All @@ -134,7 +134,7 @@
<note priority="1" from="description">Add a group to a note</note>
<context-group purpose="location">
<context context-type="sourcefile">src/app/child-dev-project/notes/note-details/note-details.component.html</context>
<context context-type="linenumber">164</context>
<context context-type="linenumber">195</context>
</context-group>
</trans-unit>
<trans-unit id="17808fe2d7d0ecfca1373602e7da72d11dcc4c0d" datatype="html">
Expand All @@ -154,7 +154,7 @@
<note priority="1" from="description">Participants of a note</note>
<context-group purpose="location">
<context context-type="sourcefile">src/app/child-dev-project/notes/note-details/note-details.component.html</context>
<context context-type="linenumber">129</context>
<context context-type="linenumber">160</context>
</context-group>
</trans-unit>
<trans-unit id="781e08965bad0a6de4dc79d832da4ec55bcd3d85" datatype="html">
Expand All @@ -163,7 +163,7 @@
<note priority="1" from="description">Add participants of a note</note>
<context-group purpose="location">
<context context-type="sourcefile">src/app/child-dev-project/notes/note-details/note-details.component.html</context>
<context context-type="linenumber">131</context>
<context context-type="linenumber">162</context>
</context-group>
</trans-unit>
<trans-unit id="5533417381380215183" datatype="html">
Expand Down Expand Up @@ -1201,6 +1201,15 @@
<context context-type="linenumber">22</context>
</context-group>
</trans-unit>
<trans-unit id="02b6f9239c84f76fe5b1c6087dba40dad21e194b" datatype="html">
<source> Download details </source>
<target state="translate"> Details herunterladen </target>
<context-group purpose="location">
<context context-type="sourcefile">src/app/child-dev-project/notes/note-details/note-details.component.html</context>
<context context-type="linenumber">51</context>
</context-group>
<note priority="1" from="description">Download note details as CSV</note>
</trans-unit>
<trans-unit id="4192457106372889898" datatype="html">
<source>since the beginning of the week</source>
<target state="translated">seit Anfang der Woche</target>
Expand Down Expand Up @@ -1228,7 +1237,7 @@
<note priority="1" from="meaning">Date input</note>
<context-group purpose="location">
<context context-type="sourcefile">src/app/child-dev-project/notes/note-details/note-details.component.html</context>
<context context-type="linenumber">31</context>
<context context-type="linenumber">62</context>
</context-group>
</trans-unit>
<trans-unit id="6d1cddbe2f61020230280a0543a70e48e43d9832" datatype="html">
Expand All @@ -1237,7 +1246,7 @@
<note priority="1" from="description">Status of a note</note>
<context-group purpose="location">
<context context-type="sourcefile">src/app/child-dev-project/notes/note-details/note-details.component.html</context>
<context context-type="linenumber">44</context>
<context context-type="linenumber">75</context>
</context-group>
</trans-unit>
<trans-unit id="483724599dbaabe37f5f82b0bee1c1faf0b27cd0" datatype="html">
Expand All @@ -1246,7 +1255,7 @@
<note priority="1" from="description">Type of Interaction when adding event</note>
<context-group purpose="location">
<context context-type="sourcefile">src/app/child-dev-project/notes/note-details/note-details.component.html</context>
<context context-type="linenumber">58</context>
<context context-type="linenumber">89</context>
</context-group>
</trans-unit>
<trans-unit id="ec3f853537ad707f8ce894ebd598335a40d787e0" datatype="html">
Expand All @@ -1255,7 +1264,7 @@
<note priority="1" from="description">placeholder when adding multiple authors</note>
<context-group purpose="location">
<context context-type="sourcefile">src/app/child-dev-project/notes/note-details/note-details.component.html</context>
<context context-type="linenumber">80</context>
<context context-type="linenumber">111</context>
</context-group>
</trans-unit>
<trans-unit id="415f73cbdba5d09762df6c89878273c3aa6da51e" datatype="html">
Expand All @@ -1264,7 +1273,7 @@
<note priority="1" from="description">Authors of a note</note>
<context-group purpose="location">
<context context-type="sourcefile">src/app/child-dev-project/notes/note-details/note-details.component.html</context>
<context context-type="linenumber">82</context>
<context context-type="linenumber">113</context>
</context-group>
</trans-unit>
<trans-unit id="c5252bb2561936719f899267ec66be730597597b" datatype="html">
Expand All @@ -1275,7 +1284,7 @@
<note priority="1" from="meaning">Placeholder</note>
<context-group purpose="location">
<context context-type="sourcefile">src/app/child-dev-project/notes/note-details/note-details.component.html</context>
<context context-type="linenumber">97</context>
<context context-type="linenumber">128</context>
</context-group>
</trans-unit>
<trans-unit id="7350eb960cd51aedbc7bb7f8bf89814947d2aa65" datatype="html">
Expand All @@ -1286,7 +1295,7 @@
<note priority="1" from="meaning">Placeholder</note>
<context-group purpose="location">
<context context-type="sourcefile">src/app/child-dev-project/notes/note-details/note-details.component.html</context>
<context context-type="linenumber">112</context>
<context context-type="linenumber">143</context>
</context-group>
</trans-unit>
<trans-unit id="7078392675701331380" datatype="html">
Expand Down
Loading

0 comments on commit fbfc016

Please sign in to comment.