rename Application to CategoryCollection #40
This commit is contained in:
@@ -3,18 +3,18 @@ import { IUserFilter } from './Filter/IUserFilter';
|
||||
import { ApplicationCode } from './Code/ApplicationCode';
|
||||
import { UserSelection } from './Selection/UserSelection';
|
||||
import { IUserSelection } from './Selection/IUserSelection';
|
||||
import { IApplicationState } from './IApplicationState';
|
||||
import { IApplication } from '@/domain/IApplication';
|
||||
import { ICategoryCollectionState } from './ICategoryCollectionState';
|
||||
import { IApplicationCode } from './Code/IApplicationCode';
|
||||
import { ICategoryCollection } from '../../../domain/ICategoryCollection';
|
||||
|
||||
export class ApplicationState implements IApplicationState {
|
||||
export class CategoryCollectionState implements ICategoryCollectionState {
|
||||
public readonly code: IApplicationCode;
|
||||
public readonly selection: IUserSelection;
|
||||
public readonly filter: IUserFilter;
|
||||
|
||||
public constructor(readonly app: IApplication) {
|
||||
this.selection = new UserSelection(app, []);
|
||||
this.code = new ApplicationCode(this.selection, app.scripting);
|
||||
this.filter = new UserFilter(app);
|
||||
public constructor(readonly collection: ICategoryCollection) {
|
||||
this.selection = new UserSelection(collection, []);
|
||||
this.code = new ApplicationCode(this.selection, collection.scripting);
|
||||
this.filter = new UserFilter(collection);
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,16 @@
|
||||
import { IScript } from '@/domain/IScript';
|
||||
import { FilterResult } from './FilterResult';
|
||||
import { IFilterResult } from './IFilterResult';
|
||||
import { IApplication } from '@/domain/IApplication';
|
||||
import { IUserFilter } from './IUserFilter';
|
||||
import { Signal } from '@/infrastructure/Events/Signal';
|
||||
import { ICategoryCollection } from '@/domain/ICategoryCollection';
|
||||
|
||||
export class UserFilter implements IUserFilter {
|
||||
public readonly filtered = new Signal<IFilterResult>();
|
||||
public readonly filterRemoved = new Signal<void>();
|
||||
public currentFilter: IFilterResult | undefined;
|
||||
|
||||
constructor(private application: IApplication) {
|
||||
constructor(private collection: ICategoryCollection) {
|
||||
|
||||
}
|
||||
|
||||
@@ -19,9 +19,9 @@ export class UserFilter implements IUserFilter {
|
||||
throw new Error('Filter must be defined and not empty. Use removeFilter() to remove the filter');
|
||||
}
|
||||
const filterLowercase = filter.toLocaleLowerCase();
|
||||
const filteredScripts = this.application.getAllScripts().filter(
|
||||
const filteredScripts = this.collection.getAllScripts().filter(
|
||||
(script) => isScriptAMatch(script, filterLowercase));
|
||||
const filteredCategories = this.application.getAllCategories().filter(
|
||||
const filteredCategories = this.collection.getAllCategories().filter(
|
||||
(category) => category.name.toLowerCase().includes(filterLowercase));
|
||||
const matches = new FilterResult(
|
||||
filteredScripts,
|
||||
|
||||
@@ -3,7 +3,7 @@ import { IUserSelection } from './Selection/IUserSelection';
|
||||
import { IApplicationCode } from './Code/IApplicationCode';
|
||||
export { IUserSelection, IApplicationCode, IUserFilter };
|
||||
|
||||
export interface IApplicationState {
|
||||
export interface ICategoryCollectionState {
|
||||
readonly code: IApplicationCode;
|
||||
readonly filter: IUserFilter;
|
||||
readonly selection: IUserSelection;
|
||||
@@ -1,17 +1,18 @@
|
||||
import { SelectedScript } from './SelectedScript';
|
||||
import { IApplication, ICategory } from '@/domain/IApplication';
|
||||
import { IUserSelection } from './IUserSelection';
|
||||
import { InMemoryRepository } from '@/infrastructure/Repository/InMemoryRepository';
|
||||
import { IScript } from '@/domain/IScript';
|
||||
import { Signal } from '@/infrastructure/Events/Signal';
|
||||
import { IRepository } from '@/infrastructure/Repository/IRepository';
|
||||
import { ICategory } from '@/domain/ICategory';
|
||||
import { ICategoryCollection } from '@/domain/ICategoryCollection';
|
||||
|
||||
export class UserSelection implements IUserSelection {
|
||||
public readonly changed = new Signal<ReadonlyArray<SelectedScript>>();
|
||||
private readonly scripts: IRepository<string, SelectedScript>;
|
||||
|
||||
constructor(
|
||||
private readonly app: IApplication,
|
||||
private readonly collection: ICategoryCollection,
|
||||
selectedScripts: ReadonlyArray<SelectedScript>) {
|
||||
this.scripts = new InMemoryRepository<string, SelectedScript>();
|
||||
if (selectedScripts && selectedScripts.length > 0) {
|
||||
@@ -40,7 +41,7 @@ export class UserSelection implements IUserSelection {
|
||||
}
|
||||
|
||||
public removeAllInCategory(categoryId: number): void {
|
||||
const category = this.app.findCategory(categoryId);
|
||||
const category = this.collection.findCategory(categoryId);
|
||||
const scriptsToRemove = category.getAllScriptsRecursively()
|
||||
.filter((script) => this.scripts.exists(script.id));
|
||||
if (!scriptsToRemove.length) {
|
||||
@@ -53,7 +54,7 @@ export class UserSelection implements IUserSelection {
|
||||
}
|
||||
|
||||
public addOrUpdateAllInCategory(categoryId: number, revert: boolean = false): void {
|
||||
const category = this.app.findCategory(categoryId);
|
||||
const category = this.collection.findCategory(categoryId);
|
||||
const scriptsToAddOrUpdate = category.getAllScriptsRecursively()
|
||||
.filter((script) =>
|
||||
!this.scripts.exists(script.id)
|
||||
@@ -70,7 +71,7 @@ export class UserSelection implements IUserSelection {
|
||||
}
|
||||
|
||||
public addSelectedScript(scriptId: string, revert: boolean): void {
|
||||
const script = this.app.findScript(scriptId);
|
||||
const script = this.collection.findScript(scriptId);
|
||||
if (!script) {
|
||||
throw new Error(`Cannot add (id: ${scriptId}) as it is unknown`);
|
||||
}
|
||||
@@ -80,7 +81,7 @@ export class UserSelection implements IUserSelection {
|
||||
}
|
||||
|
||||
public addOrUpdateSelectedScript(scriptId: string, revert: boolean): void {
|
||||
const script = this.app.findScript(scriptId);
|
||||
const script = this.collection.findScript(scriptId);
|
||||
const selectedScript = new SelectedScript(script, revert);
|
||||
this.scripts.addOrUpdateItem(selectedScript);
|
||||
this.changed.notify(this.scripts.getItems());
|
||||
@@ -105,7 +106,7 @@ export class UserSelection implements IUserSelection {
|
||||
}
|
||||
|
||||
public selectAll(): void {
|
||||
for (const script of this.app.getAllScripts()) {
|
||||
for (const script of this.collection.getAllScripts()) {
|
||||
if (!this.scripts.exists(script.id)) {
|
||||
const selection = new SelectedScript(script, false);
|
||||
this.scripts.addItem(selection);
|
||||
|
||||
Reference in New Issue
Block a user