🔍 support for search
This commit is contained in:
@@ -4,8 +4,6 @@ import applicationFile from 'js-yaml-loader!./../application.yaml';
|
||||
import { parseCategory } from './CategoryParser';
|
||||
|
||||
export function parseApplication(): Application {
|
||||
const name = applicationFile.name as string;
|
||||
const version = applicationFile.version as number;
|
||||
const categories = new Array<Category>();
|
||||
if (!applicationFile.actions || applicationFile.actions.length <= 0) {
|
||||
throw new Error('Application does not define any action');
|
||||
@@ -14,6 +12,10 @@ export function parseApplication(): Application {
|
||||
const category = parseCategory(action);
|
||||
categories.push(category);
|
||||
}
|
||||
const app = new Application(name, version, categories);
|
||||
const app = new Application(
|
||||
applicationFile.name,
|
||||
applicationFile.repositoryUrl,
|
||||
applicationFile.version,
|
||||
categories);
|
||||
return app;
|
||||
}
|
||||
|
||||
18
src/application/State/Filter/FilterResult.ts
Normal file
18
src/application/State/Filter/FilterResult.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { IFilterResult } from './IFilterResult';
|
||||
import { IScript } from '@/domain/Script';
|
||||
import { ICategory } from '@/domain/ICategory';
|
||||
|
||||
export class FilterResult implements IFilterResult {
|
||||
constructor(
|
||||
public readonly scriptMatches: ReadonlyArray<IScript>,
|
||||
public readonly categoryMatches: ReadonlyArray<ICategory>,
|
||||
public readonly query: string) {
|
||||
if (!query) { throw new Error('Query is empty or undefined'); }
|
||||
if (!scriptMatches) { throw new Error('Script matches is undefined'); }
|
||||
if (!categoryMatches) { throw new Error('Category matches is undefined'); }
|
||||
}
|
||||
public hasAnyMatches(): boolean {
|
||||
return this.scriptMatches.length > 0
|
||||
|| this.categoryMatches.length > 0;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
import { IScript, ICategory } from '@/domain/ICategory';
|
||||
|
||||
export interface IFilterMatches {
|
||||
readonly scriptMatches: ReadonlyArray<IScript>;
|
||||
export interface IFilterResult {
|
||||
readonly categoryMatches: ReadonlyArray<ICategory>;
|
||||
readonly scriptMatches: ReadonlyArray<IScript>;
|
||||
readonly query: string;
|
||||
hasAnyMatches(): boolean;
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
import { IFilterMatches } from './IFilterMatches';
|
||||
import { IFilterResult } from './IFilterResult';
|
||||
import { ISignal } from '@/infrastructure/Events/Signal';
|
||||
|
||||
export interface IUserFilter {
|
||||
readonly filtered: ISignal<IFilterMatches>;
|
||||
readonly filtered: ISignal<IFilterResult>;
|
||||
readonly filterRemoved: ISignal<void>;
|
||||
setFilter(filter: string): void;
|
||||
removeFilter(): void;
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { IFilterMatches } from './IFilterMatches';
|
||||
import { FilterResult } from './FilterResult';
|
||||
import { IFilterResult } from './IFilterResult';
|
||||
import { Application } from '../../../domain/Application';
|
||||
import { IUserFilter } from './IUserFilter';
|
||||
import { Signal } from '@/infrastructure/Events/Signal';
|
||||
|
||||
export class UserFilter implements IUserFilter {
|
||||
public readonly filtered = new Signal<IFilterMatches>();
|
||||
public readonly filtered = new Signal<IFilterResult>();
|
||||
public readonly filterRemoved = new Signal<void>();
|
||||
|
||||
constructor(private application: Application) {
|
||||
@@ -16,14 +17,17 @@ export class UserFilter implements IUserFilter {
|
||||
throw new Error('Filter must be defined and not empty. Use removeFilter() to remove the filter');
|
||||
}
|
||||
const filteredScripts = this.application.getAllScripts().filter(
|
||||
(script) => script.name.toLowerCase().includes(filter.toLowerCase()) ||
|
||||
(script) =>
|
||||
script.name.toLowerCase().includes(filter.toLowerCase()) ||
|
||||
script.code.toLowerCase().includes(filter.toLowerCase()));
|
||||
const filteredCategories = this.application.getAllCategories().filter(
|
||||
(script) => script.name.toLowerCase().includes(filter.toLowerCase()));
|
||||
|
||||
const matches: IFilterMatches = {
|
||||
scriptMatches: filteredScripts,
|
||||
categoryMatches: null,
|
||||
query: filter,
|
||||
};
|
||||
const matches = new FilterResult(
|
||||
filteredScripts,
|
||||
filteredCategories,
|
||||
filter,
|
||||
);
|
||||
|
||||
this.filtered.notify(matches);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
name: privacy.sexy
|
||||
version: 0.3.0
|
||||
repositoryUrl: https://github.com/undergroundwires/privacy.sexy
|
||||
actions:
|
||||
-
|
||||
category: Privacy cleanup
|
||||
|
||||
1
src/application/application.yaml.d.ts
vendored
1
src/application/application.yaml.d.ts
vendored
@@ -20,6 +20,7 @@ declare module 'js-yaml-loader!*' {
|
||||
interface ApplicationYaml {
|
||||
name: string;
|
||||
version: number;
|
||||
repositoryUrl: string;
|
||||
actions: ReadonlyArray<YamlCategory>;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user