Files
NativeScript/e2e/ui-tests-app/app/test-page-main-view-model.ts
Alexander Vakrilov cc97a16800 feat: Scoped Packages (#7911)
* chore: move tns-core-modules to nativescript-core

* chore: preparing compat generate script

* chore: add missing definitions

* chore: no need for http-request to be private

* chore: packages chore

* test: generate tests for tns-core-modules

* chore: add anroid module for consistency

* chore: add .npmignore

* chore: added privateModulesWhitelist

* chore(webpack): added bundle-entry-points

* chore: scripts

* chore: tests changed to use @ns/core

* test: add scoped-packages test project

* test: fix types

* test: update test project

* chore: build scripts

* chore: update build script

* chore: npm scripts cleanup

* chore: make the compat pgk work with old wp config

* test: generate diff friendly tests

* chore: create barrel exports

* chore: move files after rebase

* chore: typedoc config

* chore: compat mode

* chore: review of barrels

* chore: remove tns-core-modules import after rebase

* chore: dev workflow setup

* chore: update developer-workflow

* docs: experiment with API extractor

* chore: api-extractor and barrel exports

* chore: api-extractor configs

* chore: generate d.ts rollup with api-extractor

* refactor: move methods inside Frame

* chore: fic tests to use Frame static methods

* refactor: create Builder class

* refactor: use Builder class in tests

* refactor: include Style in ui barrel

* chore: separate compat build script

* chore: fix tslint errors

* chore: update NATIVESCRIPT_CORE_ARGS

* chore: fix compat pack

* chore: fix ui-test-app build with linked modules

* chore: Application, ApplicationSettings, Connectivity and Http

* chore: export Trace, Profiling and Utils

* refactor: Static create methods for ImageSource

* chore: fix deprecated usages of ImageSource

* chore: move Span and FormattedString to ui

* chore: add events-args and ImageSource to index files

* chore: check for CLI >= 6.2 when building for IOS

* chore: update travis build

* chore: copy Pod file to compat package

* chore: update error msg ui-tests-app

* refactor: Apply suggestions from code review

Co-Authored-By: Martin Yankov <m.i.yankov@gmail.com>

* chore: typings and refs

* chore: add missing d.ts files for public API

* chore: adress code review FB

* chore: update api-report

* chore: dev-workflow for other apps

* chore: api update

* chore: update api-report
2019-10-17 00:45:33 +03:00

105 lines
3.2 KiB
TypeScript

import { Observable } from "tns-core-modules/data/observable";
import { Button } from "tns-core-modules/ui/button";
import { Color } from "tns-core-modules/color";
import { WrapLayout } from "tns-core-modules/ui/layouts/wrap-layout";
import { alert } from "tns-core-modules/ui/dialogs";
import * as frame from "tns-core-modules/ui/frame";
import * as platform from "tns-core-modules/platform";
export class TestPageMainViewModel extends Observable {
private _colors = ["#0000cc", "#33cc33", "#0000cc"];
public basePath: string = "";
constructor(protected buttonsPanel: WrapLayout, protected _examples: Map<string, string>) {
super();
if (this.shouldLoadBtns()) {
this.sortMap(this._examples);
this.loadButtons();
}
}
protected selectExample(selectedExample: any) {
console.log(" EXAMPLE: " + selectedExample);
if (this._examples.has(selectedExample)) {
this.navigateToExample(this._examples.get(selectedExample));
} else if (selectedExample.indexOf("/") > 0) {
this.navigateToExample(selectedExample);
}
}
protected navigateToExample(exampleFullPath: string) {
try {
frame.topmost().navigate(exampleFullPath);
} catch (error) {
console.log("EXAMPLE LOAD FAILED:" + error);
alert("Error loading example: " + exampleFullPath + " \nerror: " + error && error.message);
}
}
protected loadExample(exampleName: string) {
console.log("exampleName EXAMPLE: " + exampleName);
this.selectExample(exampleName);
}
private shouldLoadBtns(): boolean {
return this.buttonsPanel.getChildrenCount() <= 0;
}
private loadButtons() {
var count = 0;
this._examples.forEach((element, key) => {
var btn = new Button();
if (platform.isAndroid) {
btn.style.height = 25;
btn.style.fontSize = 10;
btn.style.padding = 0;
} else {
btn.style.padding = 5;
}
btn.style.marginRight = 5;
btn.style.marginBottom = 5;
btn.style.color = new Color("white");
btn.style.backgroundColor = new Color(this._colors[count++ % 3]);
btn.style.borderRadius = 5;
btn.on(Button.tapEvent, function (eventData) {
let text = btn.text;
this.loadExample(text);
}, this);
btn.text = key;
btn.automationText = key;
this.buttonsPanel.addChild(btn);
});
}
private sortMap(map: Map<string, string>) {
let arrayOfKeys = new Array<string>();
map.forEach((value, key, map) => {
arrayOfKeys.push(key);
});
arrayOfKeys.sort((a, b) => {
if (a < b) {
return -1;
}
if (a > b) {
return 1;
}
return a.localeCompare(b);
});
let sortedExamples = new Map<string, string>();
arrayOfKeys.forEach((k) => {
sortedExamples.set(k, this._examples.get(k));
});
this._examples.clear();
this._examples = sortedExamples;
}
}