Skip to content

Commit

Permalink
fix filtering logic
Browse files Browse the repository at this point in the history
  • Loading branch information
jeefy committed Jun 17, 2019
1 parent 4f453b5 commit 8e2cbb9
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 23 deletions.
57 changes: 34 additions & 23 deletions src/app/notes/notes.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,36 +54,47 @@ export class NotesEffects {
return of(new DoFilterSuccess(data.notes));
} else {
const filteredNotes: Note[] = [];
const copyFilter: Filter = data.filter;
const relverFilter = 'releaseVersions';
if (data.filter) {
copyFilter.releaseVersions = [];
}

for (const note of data.notes) {
for (const key in data.filter) {
if (
key === 'releaseVersions' &&
Object.keys(data.filter[key]).indexOf(note.release_version) >= 0
) {
// Release Version is a special filter.
if (
(data.filter.isset('releaseVersions') &&
Object.keys(data.filter.get('releaseVersions')).indexOf(note.release_version) >= 0) ||
(!('releaseVersions' in data.filter) ||
!(Object.keys(data.filter.get('releaseVersions')).length > 0))
) {
if (copyFilter.isEmpty()) {
filteredNotes.push(note);
} else {
if (key in note && typeof note[key] !== 'string') {
if (
[...new Set(note[key])].filter(x => {
return data.filter[key].indexOf(x) && data.filter[key][x];
}).length > 0
) {
filteredNotes.push(note);
}
} else {
if (
key in note &&
typeof note[key] === 'string' &&
data.filter[key].trim().length > 0
) {
for (const key in data.filter) {
if (key in note && typeof note[key] !== 'string') {
if (
note[key]
.toUpperCase()
.trim()
.includes(data.filter[key].toUpperCase().trim())
[...new Set(note[key])].filter(x => {
return data.filter[key].indexOf(x) && data.filter[key][x];
}).length > 0
) {
filteredNotes.push(note);
}
} else {
if (
key in note &&
typeof note[key] === 'string' &&
data.filter[key].trim().length > 0
) {
if (
note[key]
.toUpperCase()
.trim()
.includes(data.filter[key].toUpperCase().trim())
) {
filteredNotes.push(note);
}
}
}
}
}
Expand Down
23 changes: 23 additions & 0 deletions src/app/shared/model/options.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,27 @@ export class Filter extends Options {

return friendly;
}

/**
* Method to see if a value is empty
*
* @returns a boolean
*/

public isset(key: string): boolean {
if (Object.keys(this[key]).length > 0) {
return true;
}
return false;
}

/**
* Method to return a value
*
* @returns an object or null
*/

public get(key: string): object {
return this[key];
}
}

0 comments on commit 8e2cbb9

Please sign in to comment.