Skip to content

Commit

Permalink
Merge f443272 into 5cd91b1
Browse files Browse the repository at this point in the history
  • Loading branch information
FrancescoBorzi committed Oct 26, 2019
2 parents 5cd91b1 + f443272 commit a925360
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 33 deletions.
@@ -1,34 +1,23 @@
import { Component, } from '@angular/core';

import { DTCFG } from '../../../../config/datatable.config';
import { ConditionsSearchService } from '../../../../services/search/conditions-search.service';
import { CONDITION_SOURCE_TYPES, CONDITION_SOURCE_TYPES_KEYS } from '../../../../types/conditions.type';
import { WIKI_BASE_URL } from '../../../../constants/general';
import { CONDITION_SOURCE_TYPES, CONDITION_SOURCE_TYPES_KEYS, Conditions } from '../../../../types/conditions.type';
import { ConditionsHandlerService } from '../../../../services/handlers/conditions-handler.service';
import { SelectComplexKeyComponent } from '../../shared/select-complex-key.component';

@Component({
selector: 'app-select-creature',
templateUrl: './select-conditions.component.html',
styleUrls: ['./select-conditions.component.scss']
})
export class SelectConditionsComponent {
public readonly DTCFG = DTCFG;
public readonly WIKI_BASE_URL = WIKI_BASE_URL;
export class SelectConditionsComponent extends SelectComplexKeyComponent<Conditions> {
public readonly CONDITION_SOURCE_TYPES = CONDITION_SOURCE_TYPES;
public readonly CONDITION_SOURCE_TYPES_KEYS = CONDITION_SOURCE_TYPES_KEYS;

constructor(
public selectService: ConditionsSearchService,
private handlerService: ConditionsHandlerService,
) {}

onSelect(event) {
this.handlerService.select(false, event.selected[0]);
console.log(this.handlerService.selected);
}

onCreateNew() {
this.handlerService.select(true, this.selectService.fields.getRawValue());
console.log(this.handlerService.selected);
protected handlerService: ConditionsHandlerService,
) {
super(selectService, handlerService);
}
}
23 changes: 23 additions & 0 deletions src/app/components/editors/shared/select-complex-key.component.ts
@@ -0,0 +1,23 @@
import { SearchService } from '../../../services/search/search.service';
import { ComplexKeyHandlerService } from '../../../services/handlers/complex-key.handler.service';
import { TableRow } from '../../../types/general';
import { DTCFG } from '../../../config/datatable.config';
import { WIKI_BASE_URL } from '../../../constants/general';

export class SelectComplexKeyComponent<T extends TableRow> {
public readonly DTCFG = DTCFG;
public readonly WIKI_BASE_URL = WIKI_BASE_URL;

constructor(
public selectService: SearchService<T>,
protected handlerService: ComplexKeyHandlerService<T>,
) {}

onSelect(event) {
this.handlerService.select(false, event.selected[0]);
}

onCreateNew() {
this.handlerService.select(true, this.selectService.fields.getRawValue());
}
}
Expand Up @@ -362,8 +362,7 @@
Search by entity
</a>
</li>
<!-- TODO: handler-->
<ng-container *ngIf="true">
<ng-container *ngIf="saiHandlerService.selected">
<li>
<a href="#" routerLinkActive="active" [routerLink]="'smart-ai/editor'">
SmartAI editor
Expand Down
2 changes: 2 additions & 0 deletions src/app/components/main-window/sidebar/sidebar.component.ts
Expand Up @@ -9,6 +9,7 @@ import { GameobjectHandlerService } from '../../../services/handlers/gameobject-
import { ItemHandlerService } from '../../../services/handlers/item-handler.service';
import { GossipHandlerService } from '../../../services/handlers/gossip-handler.service';
import { ConditionsHandlerService } from '../../../services/handlers/conditions-handler.service';
import { SaiHandlerService } from '../../../services/handlers/sai-handler.service';

@Component({
selector: 'app-sidebar',
Expand Down Expand Up @@ -43,6 +44,7 @@ export class SidebarComponent {
public itemHandlerService: ItemHandlerService,
public gossipHandlerService: GossipHandlerService,
public conditionsHandlerService: ConditionsHandlerService,
public saiHandlerService: SaiHandlerService,
) {
}

Expand Down
3 changes: 2 additions & 1 deletion src/app/config/app-routing.module.ts
Expand Up @@ -61,6 +61,7 @@ import { ConditionsHandlerService } from '../services/handlers/conditions-handle
import { SaiSearchExistingComponent } from '../components/editors/smart-scripts/sai-search-existing/sai-search-existing.component';
import { SaiSearchEntityComponent } from '../components/editors/smart-scripts/sai-search-entity/sai-search-entity.component';
import { SaiEditorComponent } from '../components/editors/smart-scripts/sai-editor/sai-editor.component';
import { SaiHandlerService } from '../services/handlers/sai-handler.service';

const routes: Routes = [
{
Expand Down Expand Up @@ -309,7 +310,7 @@ const routes: Routes = [
{
path: 'editor',
component: SaiEditorComponent,
canActivate: [], // TODO: add handler
canActivate: [SaiHandlerService],
},
]
},
Expand Down
Expand Up @@ -11,7 +11,6 @@ import { of, throwError } from 'rxjs';
import { MysqlError } from 'mysql';
import { getPartial } from '../../utils/helpers';


describe('SingleRowComplexKeyEditorService', () => {
let service: SingleRowComplexKeyEditorService<MockEntity>;

Expand Down
27 changes: 27 additions & 0 deletions src/app/services/handlers/complex-key.handler.service.ts
@@ -0,0 +1,27 @@
import { Router } from '@angular/router';

import { HandlerService } from './handler.service';
import { getPartial } from '../../utils/helpers';
import { TableRow } from '../../types/general';

export abstract class ComplexKeyHandlerService<T extends TableRow> extends HandlerService<T> {
/* istanbul ignore next */ // because of: https://github.com/gotwarlost/istanbul/issues/690
constructor(
protected mainEditorRoutePath: string,
protected router: Router,
protected idFields: string[],
) {
super(
mainEditorRoutePath,
router,
);
}

select(isNew: boolean, id: Partial<T>) {
super.select(isNew, this.getIdObject(id));
}

private getIdObject(input: Partial<T> | T): Partial<T> {
return getPartial<T>(input, this.idFields);
}
}
14 changes: 3 additions & 11 deletions src/app/services/handlers/conditions-handler.service.ts
Expand Up @@ -2,28 +2,20 @@ import { Injectable } from '@angular/core';
import { Router } from '@angular/router';

import { Conditions, CONDITIONS_ID_FIELDS } from '../../types/conditions.type';
import { HandlerService } from './handler.service';
import { getPartial } from '../../utils/helpers';
import { ComplexKeyHandlerService } from './complex-key.handler.service';

@Injectable({
providedIn: 'root'
})
export class ConditionsHandlerService extends HandlerService<Conditions> {
export class ConditionsHandlerService extends ComplexKeyHandlerService<Conditions> {
/* istanbul ignore next */ // because of: https://github.com/gotwarlost/istanbul/issues/690
constructor(
protected router: Router,
) {
super(
'conditions/conditions',
router,
CONDITIONS_ID_FIELDS,
);
}

select(isNew: boolean, id: Partial<Conditions>) {
super.select(isNew, this.getIdObject(id));
}

private getIdObject(input: Partial<Conditions> | Conditions): Partial<Conditions> {
return getPartial<Conditions>(input, CONDITIONS_ID_FIELDS);
}
}
2 changes: 1 addition & 1 deletion src/app/services/handlers/handler.service.ts
Expand Up @@ -10,7 +10,7 @@ export abstract class HandlerService<T extends TableRow> implements CanActivate
get selected(): string { return this._selected; }

constructor(
private mainEditorRoutePath: string,
protected mainEditorRoutePath: string,
protected router: Router,
) {}

Expand Down
21 changes: 21 additions & 0 deletions src/app/services/handlers/sai-handler.service.ts
@@ -0,0 +1,21 @@
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';

import { ComplexKeyHandlerService } from './complex-key.handler.service';
import { SAI_ID_FIELDS, SmartScripts } from '../../types/smart-scripts.type';

@Injectable({
providedIn: 'root'
})
export class SaiHandlerService extends ComplexKeyHandlerService<SmartScripts> {
/* istanbul ignore next */ // because of: https://github.com/gotwarlost/istanbul/issues/690
constructor(
protected router: Router,
) {
super(
'smart-ai/editor',
router,
SAI_ID_FIELDS,
);
}
}
6 changes: 6 additions & 0 deletions src/app/types/smart-scripts.type.ts
@@ -1,5 +1,11 @@
import { TableRow } from './general';

export const SAI_ID_FIELDS = [
'entryorguid',
'source_type',
];
export const SAI_SEARCH_FIELDS = SAI_ID_FIELDS;

export class SmartScripts extends TableRow {
entryorguid: number = 0;
source_type: number = 0;
Expand Down

0 comments on commit a925360

Please sign in to comment.