-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Viewer basic structure #1
Comments
How can we switch between the different operation components (e.g. display a value (read), then edit this value (update), and finally reload and display the updated value)? |
Project examples with one element component implementing all CRUD-operation methods in the TS file Project example with CRUD-operation components |
Knora-ui libGeneralThe knora-ui elements will be organized in one Angular lib that can then be published on npm. The lib's internal structure (its directory structure) can be similar to the structure of the previous npm libs (core, viewer etc.). Also it can consist of different modules. ViewerStructureThe viewer has a part called For the new viewer I did some prototyping which you can find here: https://github.com/tobiasschweizer/angular-lib. APIValuesAll value specific components are derived from a common base class so that they share a minimal public API: export abstract class BaseValueComponent {
@Input() abstract displayValue?: ReadValue;
@Input() mode: 'read' | 'update' | 'create' | 'search';
...
abstract restoreDisplayValue(): void;
abstract getNewValue(): CreateValue;
abstract getUpdatedValue(): UpdateValue;
} Each value component will have an optional input Each value component has to be initialized to a specific When a value is being created or updated, the new value can be obtained via
The components that implement the base class make use of reactive forms and Angular Material elements. An component's template for dates could look like this: <span [formGroup]="form">
<span [ngSwitch]="readonly">
<span class="large-field" *ngSwitchCase="true">
{{dateCtrl.value.toCalendarPeriod().periodStart.day}}-{{dateCtrl.value.toCalendarPeriod().periodStart.month}}-{{dateCtrl.value.toCalendarPeriod().periodStart.year}}
</span>
<mat-form-field class="large-field" *ngSwitchDefault>
<input matInput [matDatepicker]="picker" placeholder="Choose a date" [formControlName]="'dateValue'">
<mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
<mat-datepicker #picker></mat-datepicker>
</mat-form-field>
</span>
</span> The template's elements are bound to a In addition to the API defined on the base class, a date component could have additional specific inputs that allow for further configuration of a date (e.g., if the calendar or the era should be shown etc.) OperationsOperation components allow for displaying any type of value, make it editable or create new values. A component to display a value could look like this: export class DisplayValueComponent implements OnInit {
@Input() displayValue: ReadValue;
@Input() configuration?: IValuesConfigurationOptions;
constructor() {
}
ngOnInit() {
}
} As an input, it takes any type of value plus an configuration object as an option. This object allows for type specific configurations (e.g., how a date should be displayed). Its template contains a part that is common to all value types and also has some logic that decides which component from <div>
{{displayValue.propertyLabel}}
<br/>
{{displayValue.arkUrl}}
<span [ngSwitch]="displayValue.type">
<span *ngSwitchCase="'http://api.knora.org/ontology/knora-api/v2#TextValue'">
<lib-text-value-as-string [displayValue]="displayValue" [mode]="'read'"></lib-text-value-as-string>
</span>
<span *ngSwitchDefault>
{{displayValue.strval}}
</span>
</span>
</div> The template controls the mode of the |
Value ComponentsClassesto be rendered with mermaid: classDiagram
class BaseValueComponent {
+@Input ReadValue displayValue?
+@Input 'read' | 'update' | 'create' | 'search' mode
+void restoreDisplayValue()
+CreateValue getNewValue()*
+UpdateValue getUpdatedValue()*
+SearchValue getSearchValue()*
}
class DateValueComponent {
+@Input boolean showCalendar
+@Input boolean showEra
}
class IntegerValueComponent
BaseValueComponent <|-- DateValueComponent
BaseValueComponent <|-- IntegerValueComponent
Class - Template InteractionThe value components make use of Depending on the mode, the value component sets the template element to readonly. When a The methods TestingFor each value component units tests have to be provided. They have a to define a test host component that controls he inputs of the value component. The following test cases have to be provided:
|
classDiagram
class DisplayValuesComponent {
+@Input ReadValue[] displayValues
+@Input ViewerConfiguration viewerConfig
+@ViewChildren QueryList<BaseValueComponent> valueComponents
}
Read
Type specific configuration options are passed via the input EditFor each given value, the permissions are analysed. If sufficient, the user may edit a value (switching the value component's mode to edit). The user may then manipulate the value and either save it or abort the operation. When cancelling, the value component's method Create an additional valueFor each given value, the cardinality of its property is analysed. If a another value can be added for a property, a value component is created setting its mode to create without a display value. If the user aborts the operation, the value component has to be destroyed. If the user submits the value, it can be fetched via Delete a valueSufficient permissions provided and if allowed by the property's cardinalities, a value can be deleted. In this case, the value component is destroyed. |
Analyzing PermissionsParsing of the permission string should happen in knora-api-js-lib (see dasch-swiss/dsp-js-lib#142). The relevant information is provided by the property Analyzing CardinalitiesWhen displaying a resource's values, possibly additional values can be created. This depends on a property's cardinality for the given resource type.
Creating Values
When a value has been created, the calculation has to be redone. Deleting ValuesExisting values can be deleted if the cardinality is "0-1" or "0-n". A value can be deleted with a cardinality of "1-n" if there is at least one remaining value for the property after deletion. When a value has been deleted, the calculation has to be redone. |
The GUI attributes from the Salsah GUI ontology are not up-to-date and some attributes are missing. We can either extend the actual Salsah GUI ontology with GUI new elements or create a new ontology. TS: The GUI attributes will have an effect in the template (choosing an HTML element). |
List of GUI/Form elements needed: dasch-swiss/knora-ui/issues/358. Links to Angular Material Components included. |
Please take into account that the comment is part of the value component! |
ValidationModesI have realized that validation depends on the mode:
I think when switching the mode and/or resting the display value, the validators have to be set accordingly. Values and CommentsWhen editing a value
An updated value needs to be different from the current value (with or without a comment) or its comment needs to be different. |
@tobiasschweizer a large part of your doc here should be copied in knora-proposals in a new design file to describe this new major feature (requested by Ivan) |
@flavens Ok, I will do that, thanks! |
@tobiasschweizer Good text, but I would add some precisions:
|
@tobiasschweizer I also would like to talk about the design of the GUI elements before we start to develop all the components. I am still working on the general views but this is what I have today to start the discussion. |
@flavens Thanks for your comments! Should there be an additional input for the GUI element (e.g., HTML input or textarea for text)? |
Yes, we should try with an input. It won't be the case for each value and comment will always be a textarea. |
I think each value component can have custom configuration inputs (see #1 (comment)) in addition to those defined on the base class. |
@tobiasschweizer @mdelez some suggestions:
|
The text was updated successfully, but these errors were encountered: