Skip to content

Commit

Permalink
chore: adds more method descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
mdelez committed Feb 4, 2021
1 parent 2c88e7e commit be62277
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 8 deletions.
24 changes: 24 additions & 0 deletions src/app/project/list/list-item-form/list-item-form.component.ts
Expand Up @@ -114,6 +114,10 @@ export class ListItemFormComponent implements OnInit {
}
}

/**
* Called from the template when the plus button is clicked.
* Sends the info to make a new child node to DSP-API and refreshes the UI to show the newly added node at the end of the list.
*/
createChildNode() {

if (!this.labels.length) {
Expand Down Expand Up @@ -150,21 +154,40 @@ export class ListItemFormComponent implements OnInit {
);
}

/**
* Called from the template any time the label changes.
* Currently only implemented for labels because entering comments is not yet supported.
*
* @param data the data that was changed.
*/
handleData(data: StringLiteral[]) {
// this shouldn't run on the init...
if (!this.initComponent) {
this.labels = data;
}
}

/**
* Show action bubble with various CRUD buttons when hovered over.
*/
mouseEnter() {
this.showActionBubble = true;
}

/**
* Hide action bubble with various CRUD buttons when not hovered over.
*/
mouseLeave() {
this.showActionBubble = false;
}

/**
* Called when the 'edit' button is clicked.
*
* @param mode mode to tell DialogComponent which part of the template to show.
* @param name label of the node; for now this is always the first label in the array.
* @param iri iri of the node.
*/
openDialog(mode: string, name: string, iri?: string): void {
const dialogConfig: MatDialogConfig = {
width: '640px',
Expand All @@ -174,6 +197,7 @@ export class ListItemFormComponent implements OnInit {
data: { mode: mode, title: name, id: iri, project: this.projectIri }
};

// open the dialog box
const dialogRef = this._dialog.open(
DialogComponent,
dialogConfig
Expand Down
24 changes: 16 additions & 8 deletions src/app/project/list/list-item/list-item.component.ts
Expand Up @@ -31,24 +31,19 @@ export class ListItemComponent implements OnInit {

expandedNode: string;

loading: boolean;

constructor(
@Inject(DspApiConnectionToken) private _dspApiConnection: KnoraApiConnection,
private _errorHandler: ErrorHandlerService
) { }

ngOnInit() {
this.loading = true;

// in case of child node: do not run the following request
// in case of parent node: do not run the following request
if (!this.childNode) {
this._dspApiConnection.admin.listsEndpoint.getList(this.parentIri).subscribe(
(result: ApiResponseData<ListResponse>) => {
this.list = result.body.list.children;
this.language = result.body.list.listinfo.labels[0].language;

this.loading = false;
},
(error: ApiResponseError) => {
this._errorHandler.showMessage(error);
Expand All @@ -57,10 +52,19 @@ export class ListItemComponent implements OnInit {
}
}

/**
* Checks if parent node should show its children.
* @param id id of parent node.
*/
showChildren(id: string): boolean {
return (id === this.expandedNode);
}

/**
* Called from template when the 'expand' button is clicked.
*
* @param id id of parent node for which the 'expand' button was clicked.
*/
toggleChildren(id: string) {

if (this.showChildren(id)) {
Expand All @@ -71,10 +75,14 @@ export class ListItemComponent implements OnInit {

}

/**
* Called when the 'refreshParent' event from ListItemFormComponent is triggered.
*
* @param data info about the node; can be a root node or child node.
* @param firstNode states whether or not the node is a new child node; defaults to false.
*/
updateView(data: ListNode, firstNode: boolean = false) {

this.loading = true;

if (data instanceof ChildNodeInfo) {
this.list[data.position].labels = data.labels;
this.list[data.position].comments = data.comments;
Expand Down

0 comments on commit be62277

Please sign in to comment.