-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.js
97 lines (86 loc) · 2.75 KB
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import '../src/js/module';
class ExampleOmniboxController {
constructor($http) {
this.$http = $http;
this.omniboxResult = { tag: 'key2', title: 'hello' };
this.configOmnibox = null;
const basicConfigOmnibox = {
title: {
name: 'Title',
exactName: false,
unique: true
},
tag: {
name: 'Tag',
exactName: true,
unique: false,
background: '#d0f2f7',
autocomplete: [
{ key: 'key1', name: 'name1' },
{ key: 'key2', name: 'name2' },
{ key: 'key3', name: 'name3' },
{ key: 'key4', name: 'name4' },
{ key: 'key5', name: 'name5' }
]
}
};
this.getPokemon().then((pokemons) => {
basicConfigOmnibox.pokemon = {
name: 'Pokemon',
exactName: true,
unique: true,
background: '#ffd5d7',
autocomplete: pokemons
};
this.configOmnibox = basicConfigOmnibox;
});
this.orderOmnibox = {
keyOrderBy: 'title',
nameOrderBy: 'Title',
direction: 'asc',
fields: [
{
key: 'title',
name: 'Title'
},
{
key: 'createdAt',
name: 'Creation date'
}
]
};
this.colorOmnibox = {
historyButton: '#0f655e',
searchButton: '#0f655e'
};
}
getPokemon() {
return this.$http.get('https://pokeapi.co/api/v2/pokemon/?limit=1000').then(result => result.data.results.map(
pokemon => ({ name: pokemon.name, key: pokemon.name })
));
}
omniboxCallback(result) {
this.omniboxResult = result;
}
}
const ExampleOmniboxComponent = {
controller: ['$http', ExampleOmniboxController],
template: `
<div>
<h1>Angular Omnibox demo</h1>
<pm-angular-omnibox
ng-if="$ctrl.configOmnibox !== null"
config="$ctrl.configOmnibox"
order="$ctrl.orderOmnibox"
color="$ctrl.colorOmnibox"
default-token="'title'"
init-tokens="$ctrl.omniboxResult"
on-valid="$ctrl.omniboxCallback(result)">
</pm-angular-omnibox>
<h2>Result object</h2>
<textarea>{{ $ctrl.omniboxResult }}</textarea>
</div>
`
};
angular.module('myApp', ['angular-omnibox'])
.component('pmExampleOmnibox', ExampleOmniboxComponent);