rename Application to CategoryCollection #40

This commit is contained in:
undergroundwires
2021-01-02 03:13:01 +01:00
parent 7cc161c828
commit 6fe858d86a
42 changed files with 350 additions and 311 deletions

View File

@@ -33,7 +33,7 @@ export default class CardList extends StatefulVue {
public async mounted() {
const context = await this.getCurrentContextAsync();
this.setCategories(context.app.actions);
this.setCategories(context.collection.actions);
this.onOutsideOfActiveCardClicked((element) => {
if (hasDirective(element)) {
return;

View File

@@ -79,7 +79,7 @@ export default class CardListItem extends StatefulVue {
@Watch('categoryId')
public async updateStateAsync(value: |number) {
const context = await this.getCurrentContextAsync();
const category = !value ? undefined : context.app.findCategory(this.categoryId);
const category = !value ? undefined : context.collection.findCategory(this.categoryId);
this.cardTitle = category ? category.name : undefined;
const currentSelection = context.state.selection;
this.isAnyChildSelected = category ? currentSelection.isAnySelected(category) : false;

View File

@@ -1,18 +1,18 @@
import { IApplication } from './../../../domain/IApplication';
import { ICategory, IScript } from '@/domain/ICategory';
import { INode, NodeType } from './SelectableTree/Node/INode';
import { ICategoryCollection } from '@/domain/ICategoryCollection';
export function parseAllCategories(app: IApplication): INode[] | undefined {
export function parseAllCategories(collection: ICategoryCollection): INode[] | undefined {
const nodes = new Array<INode>();
for (const category of app.actions) {
for (const category of collection.actions) {
const children = parseCategoryRecursively(category);
nodes.push(convertCategoryToNode(category, children));
}
return nodes;
}
export function parseSingleCategory(categoryId: number, app: IApplication): INode[] | undefined {
const category = app.findCategory(categoryId);
export function parseSingleCategory(categoryId: number, collection: ICategoryCollection): INode[] | undefined {
const category = collection.findCategory(categoryId);
if (!category) {
throw new Error(`Category with id ${categoryId} does not exist`);
}

View File

@@ -19,7 +19,7 @@
import { StatefulVue } from '@/presentation/StatefulVue';
import { IScript } from '@/domain/IScript';
import { ICategory } from '@/domain/ICategory';
import { IApplicationState } from '@/application/Context/State/IApplicationState';
import { ICategoryCollectionState } from '@/application/Context/State/ICategoryCollectionState';
import { IFilterResult } from '@/application/Context/State/Filter/IFilterResult';
import { parseAllCategories, parseSingleCategory, getScriptNodeId, getCategoryNodeId, getCategoryId, getScriptId } from './ScriptNodeParser';
import SelectableTree from './SelectableTree/SelectableTree.vue';
@@ -65,9 +65,9 @@
public async initializeNodesAsync(categoryId?: number) {
const context = await this.getCurrentContextAsync();
if (categoryId) {
this.nodes = parseSingleCategory(categoryId, context.app);
this.nodes = parseSingleCategory(categoryId, context.collection);
} else {
this.nodes = parseAllCategories(context.app);
this.nodes = parseAllCategories(context.collection);
}
this.selectedNodeIds = context.state.selection.selectedScripts
.map((selected) => getScriptNodeId(selected.script));
@@ -80,13 +80,13 @@
(category: ICategory) => node.id === getCategoryNodeId(category));
}
private beginReactingToStateChanges(state: IApplicationState) {
private beginReactingToStateChanges(state: ICategoryCollectionState) {
state.selection.changed.on(this.handleSelectionChanged);
state.filter.filterRemoved.on(this.handleFilterRemoved);
state.filter.filtered.on(this.handleFiltered);
}
private setInitialState(state: IApplicationState) {
private setInitialState(state: ICategoryCollectionState) {
this.initializeNodesAsync(this.categoryId);
this.initializeFilter(state.filter.currentFilter);
}
@@ -114,7 +114,7 @@
}
}
function toggleCategoryNodeSelection(event: INodeSelectedEvent, state: IApplicationState): void {
function toggleCategoryNodeSelection(event: INodeSelectedEvent, state: ICategoryCollectionState): void {
const categoryId = getCategoryId(event.node.id);
if (event.isSelected) {
state.selection.addOrUpdateAllInCategory(categoryId, false);
@@ -122,7 +122,7 @@
state.selection.removeAllInCategory(categoryId);
}
}
function toggleScriptNodeSelection(event: INodeSelectedEvent, state: IApplicationState): void {
function toggleScriptNodeSelection(event: INodeSelectedEvent, state: ICategoryCollectionState): void {
const scriptId = getScriptId(event.node.id);
const actualToggleState = state.selection.isSelected(scriptId);
const targetToggleState = event.isSelected;

View File

@@ -37,7 +37,7 @@
@Watch('node') public async onNodeChangedAsync(node: INode) {
const context = await this.getCurrentContextAsync();
this.handler = getReverter(node, context.app);
this.handler = getReverter(node, context.collection);
}
public async onRevertToggledAsync() {

View File

@@ -1,16 +1,16 @@
import { IReverter } from './IReverter';
import { getCategoryId } from '../../../ScriptNodeParser';
import { SelectedScript } from '@/application/Context/State/Selection/SelectedScript';
import { IApplication } from '@/domain/IApplication';
import { ScriptReverter } from './ScriptReverter';
import { IUserSelection } from '@/application/Context/State/Selection/IUserSelection';
import { ICategoryCollection } from '@/domain/ICategoryCollection';
export class CategoryReverter implements IReverter {
private readonly categoryId: number;
private readonly scriptReverters: ReadonlyArray<ScriptReverter>;
constructor(nodeId: string, app: IApplication) {
constructor(nodeId: string, collection: ICategoryCollection) {
this.categoryId = getCategoryId(nodeId);
this.scriptReverters = getAllSubScriptReverters(this.categoryId, app);
this.scriptReverters = getAllSubScriptReverters(this.categoryId, collection);
}
public getState(selectedScripts: ReadonlyArray<SelectedScript>): boolean {
return this.scriptReverters.every((script) => script.getState(selectedScripts));
@@ -20,8 +20,8 @@ export class CategoryReverter implements IReverter {
}
}
function getAllSubScriptReverters(categoryId: number, app: IApplication) {
const category = app.findCategory(categoryId);
function getAllSubScriptReverters(categoryId: number, collection: ICategoryCollection) {
const category = collection.findCategory(categoryId);
if (!category) {
throw new Error(`Category with id "${categoryId}" does not exist`);
}

View File

@@ -1,5 +1,5 @@
import { SelectedScript } from '@/application/Context/State/Selection/SelectedScript';
import { IUserSelection } from '@/application/Context/State/IApplicationState';
import { IUserSelection } from '@/application/Context/State/ICategoryCollectionState';
export interface IReverter {
getState(selectedScripts: ReadonlyArray<SelectedScript>): boolean;

View File

@@ -1,13 +1,13 @@
import { INode, NodeType } from '../INode';
import { IReverter } from './IReverter';
import { ScriptReverter } from './ScriptReverter';
import { IApplication } from '@/domain/IApplication';
import { CategoryReverter } from './CategoryReverter';
import { ICategoryCollection } from '@/domain/ICategoryCollection';
export function getReverter(node: INode, app: IApplication): IReverter {
export function getReverter(node: INode, collection: ICategoryCollection): IReverter {
switch (node.type) {
case NodeType.Category:
return new CategoryReverter(node.id, app);
return new CategoryReverter(node.id, collection);
case NodeType.Script:
return new ScriptReverter(node.id);
default:

View File

@@ -1,7 +1,7 @@
import { IReverter } from './IReverter';
import { getScriptId } from '../../../ScriptNodeParser';
import { SelectedScript } from '@/application/Context/State/Selection/SelectedScript';
import { IUserSelection } from '@/application/Context/State/IApplicationState';
import { IUserSelection } from '@/application/Context/State/ICategoryCollectionState';
export class ScriptReverter implements IReverter {
private readonly scriptId: string;

View File

@@ -105,13 +105,13 @@ const selectors = new Map<SelectionState, ITypeSelector>([
[SelectionState.Standard, {
select: (context) =>
context.state.selection.selectOnly(
context.app.getScriptsByLevel(RecommendationLevel.Standard)),
context.collection.getScriptsByLevel(RecommendationLevel.Standard)),
isSelected: (context) =>
hasAllSelectedLevelOf(RecommendationLevel.Standard, context),
}],
[SelectionState.Strict, {
select: (context) =>
context.state.selection.selectOnly(context.app.getScriptsByLevel(RecommendationLevel.Strict)),
context.state.selection.selectOnly(context.collection.getScriptsByLevel(RecommendationLevel.Strict)),
isSelected: (context) =>
hasAllSelectedLevelOf(RecommendationLevel.Strict, context),
}],
@@ -119,7 +119,7 @@ const selectors = new Map<SelectionState, ITypeSelector>([
select: (context) =>
context.state.selection.selectAll(),
isSelected: (context) =>
context.state.selection.totalSelected === context.app.totalScripts,
context.state.selection.totalSelected === context.collection.totalScripts,
}],
]);
@@ -138,7 +138,7 @@ function getCurrentSelectionState(context: IApplicationContext): SelectionState
}
function hasAllSelectedLevelOf(level: RecommendationLevel, context: IApplicationContext) {
const scripts = context.app.getScriptsByLevel(level);
const scripts = context.collection.getScriptsByLevel(level);
const selectedScripts = context.state.selection.selectedScripts;
return areAllSelected(scripts, selectedScripts);
}

View File

@@ -74,7 +74,7 @@
public async mounted() {
const context = await this.getCurrentContextAsync();
this.repositoryUrl = context.app.info.repositoryWebUrl;
this.repositoryUrl = context.collection.info.repositoryWebUrl;
const filter = context.state.filter;
filter.filterRemoved.on(() => {
this.isSearching = false;

View File

@@ -40,7 +40,7 @@ export default class TheCodeArea extends StatefulVue {
public async mounted() {
const context = await this.getCurrentContextAsync();
this.editor = initializeEditor(this.theme, this.editorId, context.app.scripting.language);
this.editor = initializeEditor(this.theme, this.editorId, context.collection.scripting.language);
const appCode = context.state.code;
this.editor.setValue(appCode.current || NothingChosenCode, 1);
appCode.changed.on((code) => this.updateCode(code));

View File

@@ -21,7 +21,7 @@ import { SaveFileDialog, FileType } from '@/infrastructure/SaveFileDialog';
import { Clipboard } from '@/infrastructure/Clipboard';
import IconButton from './IconButton.vue';
import { Environment } from '@/application/Environment/Environment';
import { IApplicationCode } from '@/application/Context/State/IApplicationState';
import { IApplicationCode } from '@/application/Context/State/ICategoryCollectionState';
import { ScriptingLanguage } from '@/domain/ScriptingLanguage';
import { IApplicationContext } from '@/application/Context/IApplicationContext';
@@ -61,9 +61,9 @@ export default class TheCodeButtons extends StatefulVue {
}
function saveCode(context: IApplicationContext) {
const fileName = `privacy-script.${context.app.scripting.fileExtension}`;
const fileName = `privacy-script.${context.collection.scripting.fileExtension}`;
const content = context.state.code.current;
const type = getType(context.app.scripting.language);
const type = getType(context.collection.scripting.language);
SaveFileDialog.saveFile(content, fileName, type);
}

View File

@@ -39,7 +39,7 @@ export default class DownloadUrlListItem extends StatefulVue {
private async getDownloadUrlAsync(os: OperatingSystem): Promise<string> {
const context = await this.getCurrentContextAsync();
return context.app.info.getDownloadUrl(os);
return context.collection.info.getDownloadUrl(os);
}
}

View File

@@ -48,8 +48,8 @@ export default class TheFooter extends StatefulVue {
public async mounted() {
const context = await this.getCurrentContextAsync();
this.repositoryUrl = context.app.info.repositoryWebUrl;
this.feedbackUrl = context.app.info.feedbackUrl;
this.repositoryUrl = context.collection.info.repositoryWebUrl;
this.feedbackUrl = context.collection.info.feedbackUrl;
}
}
</script>

View File

@@ -74,8 +74,8 @@ export default class TheFooter extends StatefulVue {
}
public async mounted() {
const state = await this.getCurrentContextAsync();
const info = state.app.info;
const context = await this.getCurrentContextAsync();
const info = context.collection.info;
this.version = info.version;
this.homepageUrl = info.homepage;
this.repositoryUrl = info.repositoryWebUrl;

View File

@@ -16,7 +16,7 @@ export default class TheHeader extends StatefulVue {
public async mounted() {
const context = await this.getCurrentContextAsync();
this.title = context.app.info.name;
this.title = context.collection.info.name;
}
}
</script>

View File

@@ -13,7 +13,7 @@
import { Component, Watch } from 'vue-property-decorator';
import { StatefulVue } from './StatefulVue';
import { NonCollapsing } from '@/presentation/Scripts/Cards/NonCollapsingDirective';
import { IUserFilter } from '@/application/Context/State/IApplicationState';
import { IUserFilter } from '@/application/Context/State/ICategoryCollectionState';
@Component( {
directives: { NonCollapsing },
@@ -25,7 +25,7 @@ export default class TheSearchBar extends StatefulVue {
public async mounted() {
const context = await this.getCurrentContextAsync();
const totalScripts = context.app.totalScripts;
const totalScripts = context.collection.totalScripts;
this.searchPlaceHolder = `Search in ${totalScripts} scripts`;
this.beginReacting(context.state.filter);
}