Skip to content
Snippets Groups Projects
Commit 7fd0f89c authored by mathias.chouet's avatar mathias.chouet
Browse files

Fix #302 add session notes

parent 13221038
No related branches found
No related tags found
No related merge requests found
......@@ -506,6 +506,7 @@ export class AppComponent implements OnInit, OnDestroy, Observer {
}
// just to be sure, get rid of any Nub possibly stuck in session without any form attached
Session.getInstance().clear();
Session.getInstance().documentation = "";
}
public loadSession() {
......@@ -525,12 +526,21 @@ export class AppComponent implements OnInit, OnDestroy, Observer {
}
public loadSessionFile(f: File, info?: any) {
// notes merge detection: was there already some notes ?
const existingNotes = Session.getInstance().documentation;
// load
this.formulaireService.loadSession(f, info)
.then((data) => {
if (data.hasErrors) {
this.notificationsService.notify(this.intlService.localizeText("ERROR_PROBLEM_LOADING_SESSION"), 3500);
} else {
if (data.loaded && data.loaded.length > 0) {
// notes merge detection: was there already some notes ?
const currentNotes = Session.getInstance().documentation;
if (existingNotes !== "" && currentNotes !== existingNotes) {
this.notificationsService.notify(this.intlService.localizeText("WARNING_SESSION_LOAD_NOTES_MERGED"), 3500);
}
// go to calc or diagram depending on what was loaded
if (data.loaded.length > 1) {
this.toDiagram();
} else {
......
......@@ -31,7 +31,7 @@ import { DragDropModule } from "@angular/cdk/drag-drop";
import { TableModule } from "primeng/components/table/table";
import { KonamiModule } from "ngx-konami";
import { MarkdownModule } from "ngx-markdown";
import { MarkdownModule, MarkedOptions } from "ngx-markdown";
import { FlexLayoutModule } from "@angular/flex-layout";
import {
......@@ -133,7 +133,15 @@ const appRoutes: Routes = [
FlexLayoutModule,
HotkeyModule.forRoot(),
HttpClientModule,
MarkdownModule.forRoot(),
MarkdownModule.forRoot({
markedOptions: {
provide: MarkedOptions,
useValue: {
gfm: true,
breaks: true
}
}
}),
MatBadgeModule,
MatButtonModule,
MatButtonToggleModule,
......
<mat-card id="session-properties">
<div class="container" fxLayout="row" fxLayoutAlign="center space-evenly">
<mat-card-header>
<mat-card-title>
<h1>{{ uitextTitle }}</h1>
</mat-card-title>
</mat-card-header>
<mat-card id="session-properties">
<mat-card-content>
<mat-card-header>
<mat-card-title>
<h1>{{ uitextTitle }}</h1>
</mat-card-title>
</mat-card-header>
<mat-tab-group>
<mat-tab [label]="uitextPreview">
<markdown [data]="content" katex [katexOptions]="options"></markdown>
</mat-tab>
<mat-tab [label]="uitextEdit">
<mat-form-field>
<textarea matInput id="md-editor" [(ngModel)]="content"
cdkTextareaAutosize cdkAutosizeMinRows="15" #autosize="cdkTextareaAutosize"></textarea>
</mat-form-field>
</mat-tab>
</mat-tab-group>
<mat-card-content>
</mat-card-content>
<mat-tab-group [selectedIndex]="selectedTab">
<mat-tab [label]="uitextPreview">
<markdown [data]="content" katex [katexOptions]="options"></markdown>
</mat-tab>
<mat-tab [label]="uitextEdit">
<mat-form-field>
<textarea matInput id="md-editor" [(ngModel)]="content"
cdkTextareaAutosize cdkAutosizeMinRows="15" #autosize="cdkTextareaAutosize"></textarea>
</mat-form-field>
</mat-tab>
</mat-tab-group>
</mat-card>
</mat-card-content>
</mat-card>
</div>
mat-form-field {
width: 100%;
#session-properties {
width: 600px;
padding: 3em;
mat-form-field {
width: 100%;
textarea {
resize: none;
overflow: hidden;
textarea {
resize: none;
overflow: hidden;
}
}
}
\ No newline at end of file
import {
Component,
ViewChild,
AfterContentInit,
OnInit,
AfterViewChecked,
AfterViewInit
} from "@angular/core";
import { Component, OnInit } from "@angular/core";
import { Router } from "@angular/router";
import { Session } from "jalhyd";
import { I18nService } from "../../services/internationalisation.service";
import { Session } from "jalhyd";
import { KatexOptions } from "ngx-markdown/src/katex-options";
@Component({
......@@ -19,7 +12,9 @@ import { KatexOptions } from "ngx-markdown/src/katex-options";
templateUrl: "./session-properties.component.html",
styleUrls: ["./session-properties.component.scss"]
})
export class SessionPropertiesComponent implements /* AfterContentInit, AfterViewChecked, AfterViewInit, */ OnInit {
export class SessionPropertiesComponent implements OnInit {
public selectedTab = 0;
public options: KatexOptions;
......@@ -59,45 +54,11 @@ export class SessionPropertiesComponent implements /* AfterContentInit, AfterVie
if (! this.hasModules) {
this.router.navigate([ "/list" ]);
}
}
/* public ngAfterViewInit(): void {
// add click listener on every calculator node in the graph, that
// corresponds to an open module
this.nativeElement.querySelectorAll("g.node").forEach(item => {
if (item.id && this.formIsOpen(item.id)) {
item.style.cursor = "pointer";
item.addEventListener("click", () => {
this.openCalc(item.id);
});
}
});
}
public ngAfterContentInit(): void {
this.error = false;
mermaid.initialize({
// theme: "forest", // @TODO thème Irstea !
flowchart: {
curve: "basis"
}
});
this.nativeElement = this.diagram.nativeElement;
if (this.hasModules) {
// generate graph description
const graphDefinition = this.graphDefinition();
// draw
try {
mermaid.render("graphDiv", graphDefinition, (svgCode, bindFunctions) => {
this.nativeElement.innerHTML = svgCode;
});
} catch (e) {
console.error(e);
this.error = true;
}
// if notes content is empty, switch to editor
if (this.content === undefined || this.content === "") {
this.selectedTab = 1;
}
} */
}
public get hasModules(): boolean {
return Session.getInstance().getNumberOfNubs() > 0;
......
......@@ -423,9 +423,9 @@
"INFO_SETUP_PRECISION_CALCUL": "Computation accuracy",
"INFO_SETUP_RESTORE_DEFAULT_VALUES": "Restore default values",
"INFO_SETUP_STORE_PREFERENCES": "Save preferences",
"INFO_SETUP_TITLE": "Application setup",
"INFO_SETUP_TITLE": "Setup",
"INFO_SESSION_PROPERTIES_EDIT": "Edit",
"INFO_SESSION_PROPERTIES_PREVIEW": "Documentation",
"INFO_SESSION_PROPERTIES_PREVIEW": "Preview",
"INFO_SESSION_PROPERTIES_TITLE": "Session properties",
"INFO_SNACKBAR_DEFAULT_SETTINGS_RESTORED": "Default settings restored",
"INFO_SNACKBAR_RESULTS_CALCULATED": "Results calculated for",
......@@ -465,5 +465,6 @@
"WARNING_UPSTREAM_BOTTOM_HIGHER_THAN_WATER": "Upstream water elevation is lower or equal to bottom elevation",
"WARNING_DOWNSTREAM_BOTTOM_HIGHER_THAN_WATER": "Downstream water elevation is lower or equal to bottom elevation",
"WARNING_YN_SECTION_PENTE_NEG_NULLE_HNORMALE_INF": "Normal depth: slope is negative or zero, normal depth is infinite",
"WARNING_YN_SECTION_NON_CONVERGENCE_NEWTON_HNORMALE": "Normal depth: non convergence of the calculation (Newton's method)"
"WARNING_YN_SECTION_NON_CONVERGENCE_NEWTON_HNORMALE": "Normal depth: non convergence of the calculation (Newton's method)",
"WARNING_SESSION_LOAD_NOTES_MERGED": "Notes have been merged"
}
......@@ -311,7 +311,7 @@
"INFO_MENU_SAVE_SESSION_TITLE": "Enregistrer la session",
"INFO_MENU_SAVE_SETTINGS": "Enregistrer les paramètres",
"INFO_MENU_SELECT_CALC": "Choisir un module de calcul",
"INFO_MENU_SESSION_PROPS": "Propriétés de la session",
"INFO_MENU_SESSION_PROPS": "Notes",
"INFO_OPTION_ALL_F": "Toutes",
"INFO_OPTION_ALL": "Tous",
"INFO_OPTION_CANCEL": "Annuler",
......@@ -422,10 +422,10 @@
"INFO_SETUP_PRECISION_CALCUL": "Précision de calcul",
"INFO_SETUP_RESTORE_DEFAULT_VALUES": "Restaurer les valeurs par défaut",
"INFO_SETUP_STORE_PREFERENCES": "Enregistrer les préférences",
"INFO_SETUP_TITLE": "Paramètres de l'application",
"INFO_SESSION_PROPERTIES_EDIT": "Modifier",
"INFO_SESSION_PROPERTIES_PREVIEW": "Documentation",
"INFO_SESSION_PROPERTIES_TITLE": "Propriétés de la session",
"INFO_SETUP_TITLE": "Paramètres",
"INFO_SESSION_PROPERTIES_EDIT": "Éditer",
"INFO_SESSION_PROPERTIES_PREVIEW": "Aperçu",
"INFO_SESSION_PROPERTIES_TITLE": "Notes",
"INFO_SNACKBAR_DEFAULT_SETTINGS_RESTORED": "Paramètres par défaut restaurés",
"INFO_SNACKBAR_RESULTS_CALCULATED": "Résultats calculés pour",
"INFO_SNACKBAR_RESULTS_INVALIDATED": "Résultats invalidés pour",
......@@ -464,5 +464,6 @@
"WARNING_UPSTREAM_BOTTOM_HIGHER_THAN_WATER": "La cote de l'eau à l'amont est plus basse ou égale à la cote de fond",
"WARNING_DOWNSTREAM_BOTTOM_HIGHER_THAN_WATER": "La cote de l'eau à l'aval est plus basse ou égale à la cote de fond",
"WARNING_YN_SECTION_PENTE_NEG_NULLE_HNORMALE_INF": "Hauteur normale: pente négative ou nulle, hauteur normale infinie",
"WARNING_YN_SECTION_NON_CONVERGENCE_NEWTON_HNORMALE": "Hauteur normale: non convergence du calcul (méthode de Newton)"
"WARNING_YN_SECTION_NON_CONVERGENCE_NEWTON_HNORMALE": "Hauteur normale: non convergence du calcul (méthode de Newton)",
"WARNING_SESSION_LOAD_NOTES_MERGED": "Les notes ont été fusionnées"
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment