-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
217 lines (198 loc) · 8.67 KB
/
index.html
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<!doctype html>
<html ng-app="picnicApp">
<head>
<script type="text/javascript" src="/homey.js" data-origin="settings"></script>
<link rel="stylesheet" type="text/css" href="bootstrap.css" />
<script type="text/javascript" src="angular.js"></script>
<script type="text/javascript" src="smart-table.min.js"></script>
<script type="text/javascript" src="recipeController.js"></script>
</head>
<body>
<p data-i18n="settings.subtitle"/>
<div class="form-group">
<h2><var style="font-style:normal;" data-i18n="settings.settings"/></h2>
<div>
<div class="panel panel-default">
<div class="panel-heading">Account</div>
<div class="panel-body">
<form role="form">
<div class="form-group">
<label for="username" data-i18n="settings.username"></label>
<input class="form-control" id="username" type="text" value="" />
</div>
<div class="form-group">
<label for="password" data-i18n="settings.password"></label>
<input id="password" type="password" value="" />
</div>
<div class="form-group">
<label>Country</label>
<select id="country">
<option>NL</option>
<option>DE</option>
</select>
</div>
<div class="form-group">
<label for="authenticated" data-i18n="settings.authenticated"></label>
<div><var id="status">loading...</var></div>
</div>
<div class="form-group">
<label for="order-status" data-i18n="settings.order-status"></label>
<div><var id="order-status">loading...</var></div>
</div>
</form>
<button id="reset-order-status" class="right">Reset <var style="font-style:normal;" data-i18n="settings.order-status-button"></button>
<button id="save" class="right"><var style="font-style:normal;" data-i18n="settings.save-button"></button>
</div>
</div>
</div>
<div class="form-group">
<body ng-controller="RecipeSettingsController as rm">
<h2>Recipies</h2>
<p>Be aware that removing recipies could corrupt flows that are using that variable.</p>
<div >
<div class="panel panel-default">
<div class="panel-heading">Add recipe</div>
<div class="panel-body">
<form role="form">
<div class="form-group">
<label for="recipeName">Recipe name</label>
<input class="form-control" id="recipeName" type="text" ng-model="rm.newRecipe.name" placeholder="Name"><span class="error">{{rm.errorMessage}}</span>
</div>
<div class="form-group">
<button class="btn btn-default" type="button" ng-disabled="!rm.newRecipe.name" ng-click="rm.addRecipe()">Add recipe</button>
<button class="btn btn-default" type="button" ng-click="rm.showExport()">Export</button>
<button class="btn btn-default" type="button" ng-click="rm.showImport()">Import</button>
<button class="btn btn-default" type="button" ng-click="rm.deleteAll()">Delete All</button>
</div>
</form>
</div>
</div>
<div ng-show="rm.showExportToggle">
<b>Exported values:</b><br />
Copy selection below to save your configuration offline.
<p>
<textarea rows="6" cols="60">{{rm.recipies | json}}</textarea>
</p>
</div>
<div ng-show="rm.showImportToggle">
<b>Import values:</b><br />
Paste in the box below the exported values. Be aware that all existing values and insights will be removed.
<p>
<textarea rows="6" cols="60" ng-Model="rm.importJson"></textarea>
<div class="form-group">
<button class="btn btn-default" type="button" ng-click="rm.import()">Import</button>
</div>
</p>
</div>
<div class="panel panel-default">
<div class="panel-heading">Add ingredients to recipe</div>
<div class="panel-body">
<form role="form">
<div class="form-group">
<label>Recipe</label>
<select id=selectedRecipe>
<option ng-repeat="recipe in rm.recipies">
{{recipe.name}}
</option>
</select>
</div>
<div class="form-group">
<label for="recipeName">Ingredient (name it as precise as possible!)</label>
<input class="form-control" id="ingredientName" type="text" ng-model="rm.newIngredient.name" placeholder="Name">
</div>
<div class="form-group">
<button class="btn btn-default" type="button" ng-click="rm.addIngredient()">Add ingredient</button>
</div>
</form>
</div>
</div>
<table st-safe-src="rm.recipies" st-table="displayedCollection" class="table table-striped">
<thead>
<tr>
<th st-sort="name">Recipe</th>
<th st-sort="ingredients">Ingredients</th>
<th></th>
</tr>
<tr>
<th>
<input st-search="name" placeholder="search for recipe" class="input-sm form-control" type="search" />
</th>
<th>
</th>
<th>
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="recipe in displayedCollection" ng-include="rm.getTemplate(recipe)"></tr>
</tbody>
</table>
</div>
<script type="text/ng-template" id="display">
<td>{{recipe.name}}</td>
<td>
<select>
<option ng-repeat="ingredientItem in recipe.ingredients">
{{ingredientItem}}
</option>
</select>
</td>
<td>
<button ng-click="rm.removeRecipe(recipe)">Delete recipe</button>
</td>
</script>
<script type="text/javascript">
function onHomeyReady( Homey ){
Homey.ready();
var scope = angular.element(document.getElementById('recipeName')).scope();
scope.$apply(function() {
scope.rm.setHomey(Homey, scope);
});
var usernameElement = document.getElementById('username');
var passwordElement = document.getElementById('password');
var countryElement = document.getElementById('country');
var saveElement = document.getElementById('save');
var statusElement = document.getElementById('status');
var orderStatusElement = document.getElementById('order-status');
var resetOrderStatusElement = document.getElementById('reset-order-status');
Homey.api('GET', '/status', null, function ( err, result ) {
if ( err ) return Homey.alert( err );
if (result == "OK") {
statusElement.style.color = "green";
}
else if (result == "NOT OK" ) {
statusElement.style.color = "red";
}
statusElement.innerHTML = result;
});
Homey.api('GET', '/orderstatus', null, function ( err, result ) {
if ( err ) return Homey.alert( err );
orderStatusElement.innerHTML = result;
});
Homey.get('username', function( err, username ) {
if( err ) return Homey.alert( err );
usernameElement.value = username;
});
Homey.get('country', function( err, country ) {
if( err ) return Homey.alert( err );
countryElement.value = country.toUpperCase();
});
resetOrderStatusElement.addEventListener('click', function(e) {
Homey.api('GET', '/resetorderstatus', function( err, result ) {
if( err ) return Homey.alert(err);
window.location.reload();
});
});
saveElement.addEventListener('click', function(e) {
Homey.api('POST', '/login', { 'username': usernameElement.value, 'password': passwordElement.value, 'country': countryElement.value }, function( err, result ) {
if( err ) return Homey.alert(err);
Homey.set('username', usernameElement.value)
Homey.set('password', passwordElement.value)
window.location.reload();
});
});
}
</script>
</body>
</div>
</html>