Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Commit

Permalink
Merge pull request #73 from Disane87/dev
Browse files Browse the repository at this point in the history
fix: Items with value „null“ were breaking the board
  • Loading branch information
Disane87 authored Sep 4, 2019
2 parents 4aa4d23 + daca6ba commit c17690f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 9 deletions.
57 changes: 48 additions & 9 deletions projects/ngx-taskboard-lib/src/lib/board/board.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ export class BoardComponent implements OnInit, DoCheck, AfterViewInit {
private readonly collapseStates: Array<CollapseState> = [];

private dragItem: CardItem;
private nativeDragItem: HTMLElement;
private placeholderSet = false;
private currentDragZone: string;

Expand Down Expand Up @@ -205,13 +206,42 @@ export class BoardComponent implements OnInit, DoCheck, AfterViewInit {
}

private prepareBoard(): void {
this.generateHeadings();

this.collapseStates.push(...this.generateCollapseStates(this.hHeadings, 'h'), ...this.generateCollapseStates(this.vHeadings, 'v'));
this.taskboardService.filterChanged$.subscribe(filter => this.filter = filter);
this.checkPrerequisites().then(() => {
this.generateHeadings();

this.collapseStates.push(...this.generateCollapseStates(this.hHeadings, 'h'), ...this.generateCollapseStates(this.vHeadings, 'v'));
this.taskboardService.filterChanged$.subscribe(filter => this.filter = filter);
});



}

private checkPrerequisites(): Promise<boolean> {
if (this.checkIfPropIsObject(this.hGroupKeys[0])) {
const hasValueProperty = this.hGroupKeys.every((item: GroupHeading) => item.value != null);
if (!hasValueProperty) {
throw new Error((`Column headers are objects but field 'value' is missing in one or more items.`));
}

}

if (this.checkIfPropIsObject(this.vGroupKeys[0])) {
const hasValueProperty = this.vGroupKeys.every((item: GroupHeading) => item.value != null);
if (!hasValueProperty) {
throw new Error((`Row headers are objects but field 'value' is missing in one or more items.`));
}

}

return Promise.resolve(true);
}

private checkIfPropIsObject(prop: any): boolean {
return typeof (prop) === 'object';
}

/**
* Generates the appropiate headings
* @memberOf BoardComponent
Expand Down Expand Up @@ -297,7 +327,7 @@ export class BoardComponent implements OnInit, DoCheck, AfterViewInit {

return (this.filter !== '') ? items.filter((item, index, array) =>
(this.filterOnProperties.length > 0 ? this.filterOnProperties : Object.keys(item)).some(key => {
const found = item[key] !== undefined && typeof (item[key]) !== 'number' && ((item[key] as string).indexOf(this.filter) > -1 ? true : false);
const found = item[key] !== null && typeof (item[key]) !== 'number' && ((item[key] as string).indexOf(this.filter) > -1 ? true : false);
// found && console.info(`Searching "${item[key]}" for "${this.filter}" | Found ${found}`);
return found;
})) : items;
Expand Down Expand Up @@ -337,7 +367,10 @@ export class BoardComponent implements OnInit, DoCheck, AfterViewInit {
* @memberOf BoardComponent
*/
public getValue(item: string | GroupHeading): string {
return ((item as GroupHeading).value ? (item as GroupHeading).value : item as string);
if (item as GroupHeading) {
return ((item as GroupHeading).value ? (item as GroupHeading).value : item as string);
}
return '';
}

private determineCorrectGroupKeys(item: object): GroupKeys {
Expand Down Expand Up @@ -422,10 +455,14 @@ export class BoardComponent implements OnInit, DoCheck, AfterViewInit {
collapseItem = (collapseItem).value;
}

const foundCollapsedState = this.collapseStates.find(item => item.name === this.getValue(collapseItem)).collapsed;
// console.log('collapseState', part, foundCollapsedState);
const foundItem = this.collapseStates.find(item => item.name === this.getValue(collapseItem));
if (foundItem) {
const foundCollapsedState = foundItem.collapsed;
// console.log('collapseState', part, foundCollapsedState);

return foundCollapsedState;
return foundCollapsedState;
}
return false;
}

/**
Expand All @@ -438,6 +475,7 @@ export class BoardComponent implements OnInit, DoCheck, AfterViewInit {
*/
public dragStart(event: DragEvent, item: CardItem): void {
this.dragItem = item;
this.nativeDragItem = (event.currentTarget as HTMLElement);
this.dragStarted.emit(this.dragItem);
}

Expand Down Expand Up @@ -495,7 +533,8 @@ export class BoardComponent implements OnInit, DoCheck, AfterViewInit {
hGroup: hRow,
vGroup: vRow,
item: this.dragItem,
itemBeforeChange: dragItemBeforeChange
itemBeforeChange: dragItemBeforeChange,
nativeItemElement: this.nativeDragItem
});
this.dragItem = undefined;
}
Expand Down
1 change: 1 addition & 0 deletions projects/ngx-taskboard-lib/src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export interface ClickEvent {
/** Event which is fired when an item is dropped */
export interface DropEvent extends ClickEvent {
itemBeforeChange: object;
nativeItemElement?: HTMLElement;
}


Expand Down

0 comments on commit c17690f

Please sign in to comment.