This repository has been archived by the owner on Oct 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.html
223 lines (216 loc) · 8.18 KB
/
app.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
218
219
220
221
222
<!doctype html>
<html lang="en">
<head>
<title>Jaysee: yet another JSON visualizer</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="description" content="Yet another JSON visualizer">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1, user-scalable=yes">
<meta name="theme-color" content="#673ab7">
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-title" content="Jaysee">
<meta name="application-name" content="Jaysee">
<link rel="apple-touch-icon" sizes="57x57" href="images/apple-icon-57x57.png">
<link rel="apple-touch-icon" sizes="60x60" href="images/apple-icon-60x60.png">
<link rel="apple-touch-icon" sizes="72x72" href="images/apple-icon-72x72.png">
<link rel="apple-touch-icon" sizes="76x76" href="images/apple-icon-76x76.png">
<link rel="apple-touch-icon" sizes="114x114" href="images/apple-icon-114x114.png">
<link rel="apple-touch-icon" sizes="120x120" href="images/apple-icon-120x120.png">
<link rel="apple-touch-icon" sizes="144x144" href="images/apple-icon-144x144.png">
<link rel="apple-touch-icon" sizes="152x152" href="images/apple-icon-152x152.png">
<link rel="apple-touch-icon" sizes="180x180" href="images/apple-icon-180x180.png">
<link rel="apple-touch-icon-precomposed" href="images/apple-icon-180x180.png">
<link rel="icon" type="image/png" sizes="192x192" href="images/android-icon-192x192.png">
<link rel="icon" type="image/png" sizes="32x32" href="images/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="96x96" href="images/favicon-96x96.png">
<link rel="icon" type="image/png" sizes="16x16" href="images/favicon-16x16.png">
<link rel="manifest" href="manifest.json">
<style type="text/css">
#layout {
opacity: 0;
transition: opacity 0.5s ease-in;
}
#layout.loaded {
opacity: 1;
}
</style>
</head>
<body>
<div id="layout" class="mdl-layout mdl-js-layout mdl-layout--fixed-header">
<header id="header" class="mdl-layout__header">
<div class="mdl-layout__header-row">
<div id="title" class="mdl-layout-title"></div>
<div class="mdl-layout-spacer"></div>
<section id="section-source">
<div class="mdl-textfield mdl-js-textfield">
<input class="mdl-textfield__input" type="text" spellcheck="false" id="item-source" :value="source" @keyup.13="load">
<label class="mdl-textfield__label" for="item-source">Enter API URL here ...</label>
</div>
<button class="mdl-button mdl-js-button mdl-button--fab mdl-button--mini-fab" @click="load">
<i class="material-icons">refresh</i>
</button>
</section>
<div class="mdl-layout-spacer"></div>
<button class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon" id="hdrbtn">
<i class="material-icons">more_vert</i>
</button>
<ul class="mdl-menu mdl-js-menu mdl-js-ripple-effect mdl-menu--bottom-right" for="hdrbtn">
<li class="mdl-menu__item mdl-menu__item--full-bleed-divider">Save as JSON</li>
<li class="mdl-menu__item">About</li>
</ul>
</div>
</header>
<main id="content" class="mdl-layout__content" @scroll="scrolled">
<div id="progress" class="mdl-progress mdl-js-progress mdl-progress__indeterminate" v-show="source && !entity"></div>
<div id="toaster" class="mdl-snackbar mdl-js-snackbar">
<div class="mdl-snackbar__text"></div>
<button class="mdl-snackbar__action" type="button"></button>
</div>
<div id="scrollup">
<button class="mdl-button mdl-js-button mdl-button--fab" @click="top">
<i class="material-icons">arrow_upward</i>
</button>
</div>
<section id="section-filter" v-show="entity">
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
<input class="mdl-textfield__input" type="text" id="item-filter" v-model="filter">
<label class="mdl-textfield__label" for="item-filter">Filter</label>
</div>
</section>
<section id="section-buttons" v-show="entity">
<button class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent" @click="more">
<i class="material-icons">expand_more</i>Expand
</button>
<button class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent" @click="less">
<i class="material-icons">expand_less</i>Collapse
</button>
</section>
<section id="section-dump" v-show="entity">
<dump-table :model="entity">
<dump-row v-for="child in entity" :model="child"></dump-row>
</dump-table>
</section>
</main>
</div>
<script src="library/loader.js"></script>
<script>/* global Loader, Butter, Vue, axios */
Loader.inject([
'https://code.getmdl.io/1.2.1/material.deep_purple-orange.min.css',
'https://fonts.googleapis.com/css?family=Roboto:300,400,500,700',
'https://fonts.googleapis.com/icon?family=Material+Icons',
'https://cdnjs.cloudflare.com/ajax/libs/material-design-lite/1.3.0/material.min.js',
'https://cdnjs.cloudflare.com/ajax/libs/axios/0.15.3/axios.min.js',
'https://cdnjs.cloudflare.com/ajax/libs/vue/2.1.10/vue.min.js',
'library/butter.js'
], () => {
Loader.inject([
'app.css',
'components/dump-table.js',
'components/dump-row.js'
], start);
});
function start() {
const parameter = Butter.queryToObject(window.location.search);
document.querySelector('#layout').className += ' loaded'; // Prevents FOUC due to PageSpeed optimizations.
new Vue({ // MDL needs Vue to be initiated early.
el: '#layout',
data: {
entity: null,
source: null,
filter: ''
},
created() {
if (parameter.call) {
this.source = decodeURIComponent(parameter.call);
}
if (!this.debouncer) {
this.debouncer = Butter.debounce(this.sift);
}
},
methods: {
each(r, f) {
r.$children.forEach((c) => {
f(c);
this.each(c, f);
});
},
load() {
this.source = document.querySelector('#item-source').value;
},
sift() {
if (this.filter.length > 0) {
this.each(this.$children[0], (c) => {
if (c.$vnode.componentOptions.tag === 'dump-row') {
if (c.model[0].toString().toLowerCase().includes(this.filter) || c.model[1] && c.model[1].toString().toLowerCase().includes(this.filter)) {
c.open = true;
c.show = true;
} else {
c.show = false;
}
}
});
} else {
this.each(this.$children[0], (c) => {
if (c.$vnode.componentOptions.tag === 'dump-row') {
c.open = false;
c.show = true;
}
});
}
},
more() {
this.each(this.$children[0], (c) => {
if (c.$vnode.componentOptions.tag === 'dump-row') {
c.open = true;
}
});
},
less () {
this.each(this.$children[0], (c) => {
if (c.$vnode.componentOptions.tag === 'dump-row') {
c.open = false;
}
});
},
top() {
// Smoothly scroll to top.
const scrollToTop = (anElement, aDuration) => {
if (aDuration <= 0) {
return;
}
setTimeout(() => {
anElement.scrollTop = anElement.scrollTop-anElement.scrollTop/aDuration*10;
scrollToTop(anElement, aDuration-10);
}, 10);
};
scrollToTop(document.querySelector('#content'), 100);
},
scrolled(anEvent) {
document.querySelector('#scrollup').style = anEvent.target.scrollTop > 50 ? 'opacity: 1' : '';
}
},
watch: {
source() {
this.entity = null;
axios.get(`/api?call=${this.source}`)
.then(aResponse => {
window.history.pushState({}, 'Jaysee', `?call=${encodeURIComponent(this.source)}`);
this.entity = Butter.objectToArray(aResponse.data.data || aResponse.data); // Transform objects (and arrays) to key/value arrays.
})
.catch(anError => {
console.log(anError);
document.querySelector('#progress').style = 'display: none';
document.querySelector('#toaster').MaterialSnackbar.showSnackbar({ message: anError });
});
},
filter() {
this.debouncer();
}
}
});
}
</script>
</body>
</html>