From f5bed3c8d9410afa2dcc7b99010d3a0578bbf95c Mon Sep 17 00:00:00 2001 From: gw Date: Wed, 6 Sep 2023 10:01:01 +0200 Subject: [PATCH] misc --- apps/minimal/index.html | 2 +- .../img/CityLibrary_IDM2_simplified.svg | 360 +++++++++--------- apps/public-library/js/Book.mjs | 3 +- .../js/{BookReturn.mjs => BookTakeBack.mjs} | 14 +- apps/public-library/js/app.mjs | 2 +- src/ui/SelectMultipleItemsWidget.mjs | 4 + src/ui/vIEW.mjs | 47 ++- 7 files changed, 230 insertions(+), 202 deletions(-) rename apps/public-library/js/{BookReturn.mjs => BookTakeBack.mjs} (64%) diff --git a/apps/minimal/index.html b/apps/minimal/index.html index 7e4da60..52ba03f 100644 --- a/apps/minimal/index.html +++ b/apps/minimal/index.html @@ -2,7 +2,7 @@ - OEMjs Simple Web App Example + OEMjs Minimal App Example diff --git a/apps/public-library/img/CityLibrary_IDM2_simplified.svg b/apps/public-library/img/CityLibrary_IDM2_simplified.svg index 7307f1c..7464914 100644 --- a/apps/public-library/img/CityLibrary_IDM2_simplified.svg +++ b/apps/public-library/img/CityLibrary_IDM2_simplified.svg @@ -1,6 +1,6 @@ - + - + Zeichenblatt-1 @@ -36,16 +36,16 @@ Class - + Tabelle.3 - + Tabelle.4 - + Tabelle.5 - + Tabelle.6 @@ -55,16 +55,16 @@ Attributes id[1] : Integer {id} name[1] : String birthDate[1] : Date bio... - - - id[1] : Integer {id}name[1] : StringbirthDate[1] : Datebiography[0..1] : String + + + id[1] : Integer {id}name[1] : StringbirthDate[1] : Datebiography[0..1] : String Name «object type»Person - - - «object type»Person + + + «object type»Person Parameters @@ -86,16 +86,16 @@ Class.11 - + Tabelle.12 - + Tabelle.13 - + Tabelle.14 - + Tabelle.15 @@ -105,16 +105,16 @@ Attributes isbn : String {id} title : String year : Integer - - - isbn : String {id}title : Stringyear : Integer + + + isbn : String {id}title : Stringyear : Integer Name «object type» Book - - - «object type»Book + + + «object type»Book Parameters @@ -130,7 +130,7 @@ - + @@ -145,22 +145,22 @@ end1_mp * - - * + + * end2_name authors - - authors + + authors end2_mp * - - * + + * - + @@ -180,16 +180,16 @@ Class.25 - + Tabelle.26 - + Tabelle.27 - + Tabelle.28 - + Tabelle.29 @@ -199,16 +199,16 @@ Attributes name : String {id} address : String - - - name : String {id}address : String + + + name : String {id}address : String Name «object type» Publisher - - - «object type»Publisher + + + «object type»Publisher Parameters @@ -218,16 +218,16 @@ - - + + - + - + @@ -239,8 +239,8 @@ end1_mp 0..1 - - 0..1 + + 0..1 end2_name @@ -248,15 +248,15 @@ end2_mp * - - * + + * - + - + - + @@ -271,42 +271,46 @@ Class.83 - + Tabelle.49 - + Tabelle.50 - + Tabelle.51 - + Tabelle.52 Operations - - + onActivityEnd() + + + + onActivityEnd() + Attributes id : Integer {id} /date : Date - - - id : Integer {id}/date : Date - + + + id : Integer {id}/date : Date + Name «activity type» BookLending - - - «activity type»BookLending - + + + «activity type»BookLending + Parameters - + - + @@ -321,40 +325,44 @@ Class.121 - + Tabelle.58 - + Tabelle.59 - + Tabelle.60 - + Tabelle.61 Operations - - + onActivityEnd() + + + + onActivityEnd() + Attributes id : Integer {id} /date : Date - - - id : Integer {id}/date : Date - + + + id : Integer {id}/date : Date + Name «activity type» BookTakeBack - - - «activity type»BookTakeBack - + + + «activity type»BookTakeBack + Parameters - + @@ -366,9 +374,9 @@ - + - + @@ -380,8 +388,8 @@ end1_mp 0..1 - - 0..1 + + 0..1 end2_name @@ -389,13 +397,13 @@ end2_mp 1..* - - 1..* + + 1..* - + - + @@ -406,10 +414,10 @@ - - - - + + + + @@ -421,8 +429,8 @@ end1_mp 0..1 - - 0..1 + + 0..1 end2_name @@ -430,54 +438,54 @@ end2_mp 1..* - - 1..* + + 1..* - + - + - + - - - + + + Binary Association.104 - + end1_name - + end1_mp 0..1 - - 0..1 - + + 0..1 + end2_name - + end2_mp 1 - - 1 + + 1 - + - + @@ -494,16 +502,16 @@ Class.27 - + Tabelle.92 - + Tabelle.93 - + Tabelle.94 - + Tabelle.95 @@ -513,16 +521,16 @@ Attributes userId : Integer {key} address : String - - - userId : Integer {key}address : String + + + userId : Integer {key}address : String Name «object type» LibraryUser - - - «object type»LibraryUser + + + «object type»LibraryUser Parameters @@ -532,24 +540,24 @@ - + - + Generalization.28 - + Discriminator - - + + - + @@ -566,16 +574,16 @@ Class.50 - + Tabelle.103 - + Tabelle.104 - + Tabelle.105 - + Tabelle.106 @@ -585,62 +593,62 @@ Attributes id : Integer {id} status : BookCopyStatusEL - - - id : Integer {id}status : BookCopyStatusEL + + + id : Integer {id}status : BookCopyStatusEL Name «object type» BookCopy - - - «object type»BookCopy + + + «object type»BookCopy Parameters - + - - + + - + - + Binary Association.111 - + end1_name - + end1_mp * - - * - + + * + end2_name - + end2_mp 1 - - 1 + + 1 - + - + @@ -662,56 +670,56 @@ Attributes AVAILABLE LENDED - - - AVAILABLELENDED + + + AVAILABLELENDED Name «enumeration» BookCopyStatusEL - - - «enumeration»BookCopyStatusEL + + + «enumeration»BookCopyStatusEL - + - - + + - - - + + + Binary Association.176 - + end1_name - + end1_mp 0..1 - - 0..1 - + + 0..1 + end2_name - + end2_mp 1 - - 1 + + 1 - + diff --git a/apps/public-library/js/Book.mjs b/apps/public-library/js/Book.mjs index 9b169ed..ad8ea46 100644 --- a/apps/public-library/js/Book.mjs +++ b/apps/public-library/js/Book.mjs @@ -6,13 +6,14 @@ import {dt} from "../../../src/datatypes.mjs"; * @class */ class Book extends bUSINESSoBJECT { - constructor ({isbn, title, year, publisher, authors, reserved=false}) { + constructor ({isbn, title, year, publisher, authors, reserved=false, bookCopies}) { super( isbn); this.title = title; this.year = year; this.authors = authors; if (publisher) this.publisher = publisher; this.reserved = reserved; + if (bookCopies) this.publisher = bookCopies; } } Book.properties = { diff --git a/apps/public-library/js/BookReturn.mjs b/apps/public-library/js/BookTakeBack.mjs similarity index 64% rename from apps/public-library/js/BookReturn.mjs rename to apps/public-library/js/BookTakeBack.mjs index f59083c..94040f6 100644 --- a/apps/public-library/js/BookReturn.mjs +++ b/apps/public-library/js/BookTakeBack.mjs @@ -1,11 +1,12 @@ import bUSINESSaCTIVITY from "../../../src/bUSINESSaCTIVITY.mjs"; -import {BookCopyStatusEL} from "./BookCopy.mjs"; +import {BookCopy, BookCopyStatusEL} from "./BookCopy.mjs"; +import app from "./app.mjs"; /** * Business activity type BookLending * @class */ -class BookReturn extends bUSINESSaCTIVITY { +class BookTakeBack extends bUSINESSaCTIVITY { constructor ({returner, bookCopies}) { super(); this.returner = returner; @@ -14,18 +15,19 @@ class BookReturn extends bUSINESSaCTIVITY { onActivityEnd() { for (const bc of this.bookCopies) { bc.status = BookCopyStatusEL.AVAILABLE; + app.storageManager.update( BookCopy, bc.id, {status: bc.status}); } } } -BookReturn.properties = { +BookTakeBack.properties = { "returner": {range:"Person", label:"Returner"}, "bookCopies": {range:"BookCopy", label:"Returned book copies", minCard: 1, maxCard: Infinity, selectionRangeFilter: bc => bc.status === BookCopyStatusEL.LENDED} } // menu item text and UI title -BookReturn.activityPhrase = "Take back books"; +BookTakeBack.activityPhrase = "Take back books"; // collect classes in a map -bUSINESSaCTIVITY.classes["BookReturn"] = BookReturn; +bUSINESSaCTIVITY.classes["BookTakeBack"] = BookTakeBack; -export default BookReturn; \ No newline at end of file +export default BookTakeBack; \ No newline at end of file diff --git a/apps/public-library/js/app.mjs b/apps/public-library/js/app.mjs index 8e9a545..2de44d1 100644 --- a/apps/public-library/js/app.mjs +++ b/apps/public-library/js/app.mjs @@ -9,7 +9,7 @@ import Book from "./Book.mjs"; import {BookCopy, BookCopyStatusEL} from "./BookCopy.mjs"; import BookReturnReminder from "./BookReturnReminder.mjs"; import BookLending from "./BookLending.mjs"; -import BookReturn from "./BookReturn.mjs"; +import BookTakeBack from "./BookTakeBack.mjs"; // import framework code files import sTORAGEmANAGER from "../../../src/storage/sTORAGEmANAGER.mjs"; diff --git a/src/ui/SelectMultipleItemsWidget.mjs b/src/ui/SelectMultipleItemsWidget.mjs index 971d23e..8ebcf01 100644 --- a/src/ui/SelectMultipleItemsWidget.mjs +++ b/src/ui/SelectMultipleItemsWidget.mjs @@ -291,6 +291,10 @@ class SelectMultipleItemsWidget extends HTMLElement { this.fillSelectedItemsList(); this.fillSelectionListWithOptions(); } + reset() { + this.selection = []; + this.refresh(); + } static createDeleteButton() { const el = document.createElement("button"); el.type = "button"; diff --git a/src/ui/vIEW.mjs b/src/ui/vIEW.mjs index d580800..10c077e 100644 --- a/src/ui/vIEW.mjs +++ b/src/ui/vIEW.mjs @@ -537,7 +537,6 @@ class vIEW { })); break; case "C": //================ CREATE ============================ - this.resetViewFields(); // create form fields for all view fields createUiElemsForViewFields(); // create save and back buttons @@ -586,8 +585,8 @@ class vIEW { } if (formEl.checkValidity()) { view.userActions["createRecord"]( slots); - // clear view fields, otherwise they are sent again even if the form is empty! - view.resetViewFields(); + formEl.reset(); + view.reset(); } }); break; @@ -604,14 +603,7 @@ class vIEW { selectEl = formEl[slots.name]; // when an entity is selected, populate the form with its data selectEl.addEventListener("change", async function () { - const formFields = formEl.elements; var id = selectEl.value; - // reset form fields - formEl.reset(); - // reset custom validity - for (let i=0; i < formFields.length; i++) { - formFields[i].setCustomValidity(""); - } if (id) { // parse id if integer value if (dt.isIntegerType( stdIdRange)) id = parseInt( id); const obj = await vIEW.app.storageManager.retrieve( mc, id); @@ -662,7 +654,8 @@ class vIEW { if (dt.isIntegerType( stdIdRange)) id = parseInt( id); // map UI event to a user action defined by the view view.userActions["updateRecord"]( id, slots); - view.resetViewFields(); + formEl.reset(); + view.reset(); } }); break; @@ -707,10 +700,11 @@ class vIEW { if (selectEl && id) { selectEl.remove( selectEl.selectedIndex); } + formEl.reset(); + view.reset(); }); break; default: // activity UI - this.resetViewFields(); // create form fields for all view fields createUiElemsForViewFields(); // create delete and back buttons @@ -766,8 +760,8 @@ class vIEW { if (formEl.checkValidity()) { // map UI event to a user action defined by the view await view.userActions["performActivity"]( slots); - // clear view fields, otherwise they are sent again even if the form is empty! - view.resetViewFields(); + formEl.reset(); + view.reset(); } }); } @@ -783,9 +777,7 @@ class vIEW { */ } /** - * Generic setter for view fields, takes also care of bottom-up data-binding - * (from view field to corresponding UI widget) - * this = view object + * Reset view fields * @method * @author Gerd Wagner * TODO: support derived and dependent view fields @@ -802,6 +794,27 @@ class vIEW { } } } + /** + * Reset view + * @method + * @author Gerd Wagner + * TODO: support derived and dependent view fields + */ + reset() { + for (const f of Object.keys( this.fields)) { + const fldDef = this.fields[f], + uiEl = this.dataBinding[f]; + if ("setCustomValidity" in uiEl) uiEl.setCustomValidity(""); + else uiEl.reset(); + if (fldDef.maxCard > 1) { + this.fldValues[f] = []; + } else if (fldDef.range in dt.classes) { + this.fldValues[f] = undefined; // view field holds ID strings + } else { + this.fldValues[f] = dt.getDefaultValue( fldDef.range); + } + } + } /** * Generic setter for view fields, takes also care of bottom-up data-binding * (from view field to corresponding UI widget)