Skip to content

Commit

Permalink
feat(SAI): display Timed Actionlists of creatures (#472)
Browse files Browse the repository at this point in the history
* feat(SAI): display Timed Actionlists of creatures

* chore: wip

* test: add checks
  • Loading branch information
FrancescoBorzi committed Mar 16, 2020
1 parent f853ef7 commit a9172ad
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 37 deletions.
42 changes: 24 additions & 18 deletions src/app/shared/modules/sai-editor/sai-editor.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,16 @@
<div class="form-row">
<div class="form-group col-7">
<label class="control-label" id="label-event-param1">
<ng-container *ngIf="!isTimedActionlists">
{{ getName('param1', EVENT_PARAM1_NAMES[selectedEvent]) }} <i
class="fas fa-info-circle ml-1" [placement]="'auto'"
[hidden]="!EVENT_PARAM1_TOOLTIPS[selectedEvent]"
[tooltip]="EVENT_PARAM1_TOOLTIPS[selectedEvent]"
></i>
</ng-container>
<ng-container *ngIf="isTimedActionlists">
minTimer
</ng-container>
<ng-container *ngIf="!isTimedActionlists">
{{ getName('param1', EVENT_PARAM1_NAMES[selectedEvent]) }} <i
class="fas fa-info-circle ml-1" [placement]="'auto'"
[hidden]="!EVENT_PARAM1_TOOLTIPS[selectedEvent]"
[tooltip]="EVENT_PARAM1_TOOLTIPS[selectedEvent]"
></i>
</ng-container>
<ng-container *ngIf="isTimedActionlists">
minTimer
</ng-container>
</label>
</div>

Expand All @@ -166,7 +166,7 @@
class="fas fa-info-circle ml-1" [placement]="'auto'"
[hidden]="!EVENT_PARAM2_TOOLTIPS[selectedEvent]"
[tooltip]="EVENT_PARAM2_TOOLTIPS[selectedEvent]"
></i>
></i>
</ng-container>
<ng-container *ngIf="isTimedActionlists">
maxTimer
Expand Down Expand Up @@ -510,12 +510,12 @@
[rowHeight]="DTCFG.rowHeight"
[selectionType]="DTCFG.selectionType"
(select)='editorService.onRowSelection($event)'>
<ngx-datatable-column [width]="30" [sortable]="false">
<ngx-datatable-column [minWidth]="30" [maxWidth]="30" [sortable]="false">
<ng-template let-row="row" ngx-datatable-cell-template>
<i [hidden]="!editorService.isRowSelected(row)" class="fas fa-chevron-right"></i>
</ng-template>
</ngx-datatable-column>
<ngx-datatable-column [minWidth]="50" [maxWidth]="70" name="id" prop="id"></ngx-datatable-column>
<ngx-datatable-column [minWidth]="50" [maxWidth]="60" name="id" prop="id"></ngx-datatable-column>
<ngx-datatable-column [minWidth]="50" [maxWidth]="70" name="event" prop="event_type"></ngx-datatable-column>
<ngx-datatable-column [minWidth]="50" [maxWidth]="70" name="action" prop="action_type"></ngx-datatable-column>
<ngx-datatable-column [minWidth]="50" [maxWidth]="70" name="target" prop="target_type"></ngx-datatable-column>
Expand All @@ -529,11 +529,17 @@
</div>
</div>


<keira-timed-actionlist
*ngIf="showTimedActionlists"
[creatureId]="entryOrGuid"
></keira-timed-actionlist>
<div *ngIf="showTimedActionlists">
<hr class="mt-0">
<p class="lead">
Creature's Timed Actionlists
<i
class="fas fa-info-circle ml-1" [placement]="'auto'"
[tooltip]="'All smart_scripts having source_type = 9 and entryorguid between CreatureID * 100 and CreatureID * 100 + 100'"
></i>
</p>
<keira-timed-actionlist [creatureId]="entryOrGuid"></keira-timed-actionlist>
</div>

</div>
</div>
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@

<ngx-datatable
class="bootstrap table table-striped text-center"
[rows]="timedActionlists$ | async"
[headerHeight]="DTCFG.headerHeight"
[footerHeight]="DTCFG.footerHeight"
[columnMode]="DTCFG.columnMode"
[rowHeight]="DTCFG.rowHeight"
>
<ngx-datatable-column [minWidth]="100" [maxWidth]="100" name="entryorguid" prop="entryorguid"></ngx-datatable-column>
<ngx-datatable-column [minWidth]="50" [maxWidth]="60" name="id" prop="id"></ngx-datatable-column>
<ngx-datatable-column [minWidth]="50" [maxWidth]="70" name="action" prop="action_type"></ngx-datatable-column>
<ngx-datatable-column [minWidth]="50" [maxWidth]="70" name="target" prop="target_type"></ngx-datatable-column>
<ngx-datatable-column [minWidth]="50" [maxWidth]="70" name="link" prop="link"></ngx-datatable-column>
<ngx-datatable-column [minWidth]="50" [maxWidth]="70" name="phase" prop="event_phase_mask"></ngx-datatable-column>
<ngx-datatable-column [minWidth]="50" [maxWidth]="70" name="chance" prop="event_chance"></ngx-datatable-column>
<ngx-datatable-column name="comment" prop="comment"></ngx-datatable-column>
</ngx-datatable>
Original file line number Diff line number Diff line change
@@ -1,25 +1,59 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { async, TestBed } from '@angular/core/testing';

import { TimedActionlistComponent } from './timed-actionlist.component';
import { PageObject } from '@keira-testing/page-object';
import { Component, ViewChild } from '@angular/core';
import { MysqlQueryService } from '@keira-shared/services/mysql-query.service';
import { SmartScripts } from '@keira-types/smart-scripts.type';
import { of } from 'rxjs';
import { NgxDatatableModule } from '@swimlane/ngx-datatable';

@Component({
template: `<keira-timed-actionlist [creatureId]="creatureId"></keira-timed-actionlist>`
})
class TestHostComponent {
@ViewChild(TimedActionlistComponent) child: TimedActionlistComponent;
creatureId: string;
}

class TimedActionlistPage extends PageObject<TestHostComponent> {}

describe('TimedActionlistComponent', () => {
let component: TimedActionlistComponent;
let fixture: ComponentFixture<TimedActionlistComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ TimedActionlistComponent ]
declarations: [TimedActionlistComponent, TestHostComponent],
imports: [NgxDatatableModule],
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(TimedActionlistComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
const setup = () => {
const fixture = TestBed.createComponent(TestHostComponent);
const host = fixture.componentInstance;
const page = new TimedActionlistPage(fixture);
const queryService = TestBed.inject(MysqlQueryService);
page.detectChanges();
return { page, host, queryService };
};

it('should create', () => {
expect(component).toBeTruthy();
const { page, queryService, host } = setup();
const id = '1234';
const timedActionlists: SmartScripts[] = [new SmartScripts(), new SmartScripts()];
timedActionlists[0].entryorguid = 111;
timedActionlists[0].id = 1;
timedActionlists[1].entryorguid = 222;
timedActionlists[1].id = 2;
spyOn(queryService, 'getTimedActionlists').and.returnValue(of(timedActionlists));

host.creatureId = id;
host.child.ngOnChanges();
page.detectChanges();

expect(page.getDatatableCell('ngx-datatable', 0, 0).innerText).toContain(String(timedActionlists[0].entryorguid));
expect(page.getDatatableCell('ngx-datatable', 0, 1).innerText).toContain(String(timedActionlists[0].id));
expect(page.getDatatableCell('ngx-datatable', 1, 0).innerText).toContain(String(timedActionlists[1].entryorguid));
expect(page.getDatatableCell('ngx-datatable', 1, 1).innerText).toContain(String(timedActionlists[1].id));
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { ChangeDetectionStrategy, Component, Input, OnChanges } from '@angular/core';
import { Observable } from 'rxjs';

import { MysqlQueryService } from '@keira-shared/services/mysql-query.service';
import { SmartScripts } from '@keira-types/smart-scripts.type';
import { DTCFG } from '@keira-config/datatable.config';

@Component({
selector: 'keira-timed-actionlist',
Expand All @@ -8,19 +12,19 @@ import { MysqlQueryService } from '@keira-shared/services/mysql-query.service';
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class TimedActionlistComponent implements OnChanges {
public readonly DTCFG = DTCFG;
@Input() creatureId: string|number;

private _timedActionLists$: Observable<SmartScripts[]>;
get timedActionlists$(): Observable<SmartScripts[]> {
return this._timedActionLists$;
}

constructor(
private queryService: MysqlQueryService,
) { }

/* istanbul ignore next */ // TODO: write test once this component is complete
ngOnChanges(): void {
if (!!this.creatureId) {
this.queryService.getTimedActionlists(this.creatureId).subscribe((result) => {
console.log(result);
});
}
ngOnChanges() {
this._timedActionLists$ = this.queryService.getTimedActionlists(this.creatureId);
}

}

0 comments on commit a9172ad

Please sign in to comment.