Skip to content

Commit 0d6fb1c

Browse files
author
Robert Jackson
committed
Move shared upload functionality into simple modal.
1 parent 0d973ca commit 0d6fb1c

File tree

6 files changed

+89
-49
lines changed

6 files changed

+89
-49
lines changed

app/controllers/application.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import Ember from 'ember';
2+
import fetch from "ember-network/fetch";
3+
4+
const {
5+
inject
6+
} = Ember;
7+
8+
export default Ember.Controller.extend({
9+
graph: inject.service(),
10+
11+
actions: {
12+
parseFile(event) {
13+
let reader = new FileReader();
14+
reader.onload = (e) => {
15+
var contents = e.target.result;
16+
this.get('graph').setGraph(JSON.parse(contents));
17+
this.set('showUploadModal', false);
18+
};
19+
20+
reader.readAsText(event.target.files[0]);
21+
},
22+
23+
useSample(url) {
24+
fetch(url)
25+
.then((response) => {
26+
return response.json();
27+
})
28+
.then((contents) => {
29+
this.get('graph').setGraph(contents);
30+
this.set('showUploadModal', false);
31+
});
32+
}
33+
}
34+
})

app/controllers/index.js

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,9 @@
11
import Ember from 'ember';
2-
import fetch from "ember-network/fetch";
3-
import config from '../config/environment';
42

53
const {
64
inject
75
} = Ember;
86

97
export default Ember.Controller.extend({
10-
graph: inject.service(),
11-
12-
actions: {
13-
parseFile(event) {
14-
let reader = new FileReader();
15-
reader.onload = (e) => {
16-
var contents = e.target.result;
17-
this.get('graph').setGraph(JSON.parse(contents));
18-
};
19-
20-
reader.readAsText(event.target.files[0]);
21-
},
22-
23-
useSample(url) {
24-
fetch(url)
25-
.then((response) => {
26-
return response.json();
27-
})
28-
.then((contents) => {
29-
this.get('graph').setGraph(contents);
30-
});
31-
}
32-
}
8+
graph: inject.service()
339
});

app/templates/application.hbs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
<div class="nav-left">
44
{{link-to 'Home' 'index' class="nav-item is-tab" activeClass="is-active"}}
55
{{link-to 'Slow Nodes' 'slow-nodes' class="nav-item is-tab" activeClass="is-active"}}
6+
<a class="nav-item" {{action (action (mut showUploadModal) true)}}>
7+
Upload Data
8+
</a>
69
</div>
710
<div class="nav-center">
811
<p class="nav-item title">
@@ -19,4 +22,33 @@
1922
</nav>
2023
</section>
2124

25+
<div class="modal {{if showUploadModal 'is-active'}}">
26+
<div class="modal-background"></div>
27+
<div class="modal-content">
28+
<div class="box">
29+
<form>
30+
<div class="control is-grouped">
31+
<label class="label">Upload the output of <code>BROCCOLI_VIZ=1 ember build</code>:</label>
32+
<p class="control">
33+
<input name="file-upload" type="file" onchange={{action 'parseFile'}}>
34+
</p>
35+
</div>
36+
<div class="control is-grouped">
37+
<label class="label">Sample File:</label>
38+
<p class="control">
39+
<span class="select is-small">
40+
<select onchange={{action 'useSample' value="target.value"}}>
41+
<option selected disabled>Choose sample file</option>
42+
<option value="./broccoli-viz-files/initial-build-canary-ember-cli-20170206.json">Empty Project - 2017-02-06</option>
43+
<option value="./broccoli-viz-files/ghost-initial-build-canary-ember-cli-20170206.json">Ghost Admin Client - 2017-02-06</option>
44+
</select>
45+
</span>
46+
</p>
47+
</div>
48+
</form>
49+
</div>
50+
</div>
51+
<button class="modal-close" {{action (action (mut showUploadModal) false)}}></button>
52+
</div>
53+
2254
{{outlet}}

app/templates/components/slow-node-times.hbs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
1-
{{input value=pluginNameFilter placeholder="Filter by plugin name..."}}
2-
<label>Group by Plugin Name{{input type="checkbox" checked=groupByPluginName}}</label>
3-
<button {{action (action (mut pluginNameFilter) '')}}>Clear</button>
1+
<div class="level">
2+
<div class="level-left">
3+
<div class="level-item">
4+
<p class="control">
5+
{{input value=pluginNameFilter placeholder="Filter by plugin name..."}}
6+
</p>
7+
</div>
8+
<div class="level-item">
9+
<p class="control">
10+
<label class="checkbox">
11+
{{input type="checkbox" checked=groupByPluginName}}
12+
Group by Plugin Name
13+
</label>
14+
</p>
15+
</div>
16+
</div>
17+
<div class="level-right">
18+
<p class="control">
19+
<button class="button" {{action (action (mut pluginNameFilter) '')}}>Clear</button>
20+
</p>
21+
</div>
22+
</div>
423

524
<table class="table is-striped">
625
<thead>

app/templates/index.hbs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
1-
<form>
2-
<div>
3-
<label for="file-upload">Upload the output of <code>BROCCOLI_VIZ=1 ember build</code>:</label>
4-
<input name="file-upload" type="file" onchange={{action 'parseFile'}}>
5-
</div>
6-
<div>
7-
<select onchange={{action 'useSample' value="target.value"}}>
8-
<option selected disabled>Choose sample file</option>
9-
<option value="./broccoli-viz-files/initial-build-canary-ember-cli-20170206.json">Empty Project - 2017-02-06</option>
10-
<option value="./broccoli-viz-files/ghost-initial-build-canary-ember-cli-20170206.json">Ghost Admin Client - 2017-02-06</option>
11-
</select>
12-
</div>
13-
</form>
14-
151
{{! basic-tree graphData=graphData}}
162

173
{{! useful for testing... }}

app/templates/slow-nodes.hbs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1 @@
1-
<form>
2-
<div>
3-
<label for="file-upload">Upload the `instrumentation.*.json` output of <code>BROCCOLI_VIZ=1 ember build</code>:</label>
4-
<input name="file-upload" type="file" onchange={{action 'parseFile'}}>
5-
</div>
6-
</form>
7-
81
{{slow-node-times data=graph.graph}}

0 commit comments

Comments
 (0)