Skip to content

Commit 69a4518

Browse files
committed
Show progress with completion percentage #205
* Add ProgressBar.js library * Add new progress bar with completion percentage Signed-off-by: Jillian Daguil <[email protected]>
1 parent d67df96 commit 69a4518

File tree

9 files changed

+2590
-32
lines changed

9 files changed

+2590
-32
lines changed

assets/app/css/main.css

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -343,11 +343,14 @@ div.dataTables_scrollHead th:first-child {
343343
text-align: center;
344344
}
345345

346-
.progress .indicator {
347-
position: relative;
348-
width: 50px;
349-
height: 50px;
346+
.progress .progressbar {
347+
position: static;
348+
width: 100%;
349+
height: 100%;
350350
margin: auto;
351+
}
352+
353+
.progress .indeterminate {
351354
border: 6px solid #B4DDF8;
352355
border-radius: 50%;
353356
border-top: 6px solid #3498db;

assets/app/js/aboutCodeDB.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ class AboutCodeDB {
170170
}
171171

172172
// Add rows to the flattened files table from a ScanCode json object
173-
addFromJson(jsonFileName, aboutCodeVersion) {
173+
addFromJson(jsonFileName, aboutCodeVersion, onProgressUpdate) {
174174
if (!jsonFileName) {
175175
throw new Error("Invalid json file name: " + jsonFileName);
176176
}
@@ -223,6 +223,7 @@ class AboutCodeDB {
223223
const currProgress = Math.round(index/files_count*100);
224224
if (currProgress > progress) {
225225
progress = currProgress;
226+
onProgressUpdate(progress);
226227
console.log("Progress: "
227228
+ `${progress}% `
228229
+ `(${index}/${files_count})`);

assets/app/js/progress.js

Lines changed: 50 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
22
#
33
# Copyright (c) 2017 nexB Inc. and others. All rights reserved.
4-
# https://nexb.com and https://github.com/nexB/scancode-toolkit/
5-
# The ScanCode software is licensed under the Apache License version 2.0.
4+
# https://nexb.com and https://github.com/nexB/aboutcode-manager
5+
# The AboutCode Manager software is licensed under the Apache License version 2.0.
66
# AboutCode is a trademark of nexB Inc.
77
#
88
# You may not use this software except in compliance with the License.
@@ -16,31 +16,36 @@
1616

1717
class Progress {
1818
constructor(elementId, options) {
19+
this.id = elementId;
1920
this.container = $(elementId);
2021
this.options = options;
2122
}
2223

23-
show() {
24-
if (!this.progressContainer) {
25-
this.progress = $("<div>", {
26-
class: "progress"
27-
});
28-
this.progressTitle = $("<h4>", {
29-
text: this.options.title,
30-
class: "title"
31-
});
32-
this.progressIndicator = $("<div>", {
33-
class: "indicator"
34-
});
35-
36-
this.progress
37-
.append(this.progressTitle)
38-
.append(this.progressIndicator);
24+
showIndeterminate() {
25+
this._show(this._createProgressElement('indeterminate'));
26+
}
3927

40-
this.progressContainer =
41-
this.container.clone().empty().append(this.progress);
28+
showDeterminate() {
29+
this._show(this._createProgressElement('determinate'));
30+
this.progressBar = new ProgressBar
31+
.Circle(`${this.id} .determinate`, {
32+
color: '#3D7AFC',
33+
strokeWidth: 4,
34+
trailWidth: 1,
35+
step: function(state, circle) {
36+
const value = Math.round(circle.value() * 100);
37+
if (value === 0) {
38+
circle.setText('');
39+
} else {
40+
circle.setText(`${value}%`);
41+
}
42+
}
43+
});
44+
}
4245

43-
this.container.before(this.progressContainer);
46+
update(progress) {
47+
if (this.progressBar) {
48+
this.progressBar.animate(progress);
4449
}
4550
}
4651

@@ -50,6 +55,30 @@ class Progress {
5055
this.progressContainer = null;
5156
}
5257
}
58+
59+
_show(progressBar) {
60+
if (!this.progressContainer) {
61+
this.progressContainer =
62+
this.container.clone().empty().append(progressBar);
63+
this.container.before(this.progressContainer);
64+
}
65+
}
66+
67+
_createProgressElement(progressbarClass) {
68+
const progressElement = $(
69+
`<div class='progress'>
70+
<h4 class='title'>${this.options.title}</h4>
71+
<div class='progressbar ${progressbarClass}'></div>
72+
</div>`);
73+
74+
if (this.options.size) {
75+
progressElement.find('.progressbar').css({
76+
"width": `${this.options.size}px`,
77+
"height": `${this.options.size}px`
78+
});
79+
}
80+
return progressElement;
81+
}
5382
}
5483

5584
module.exports = Progress;

assets/app/js/renderer.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,15 +245,21 @@ $(document).ready(function () {
245245
dbStorage: fileName,
246246
});
247247

248-
const progress =
249-
new Progress("#content", {title: "Creating Database"});
248+
const progressbar =
249+
new Progress("#content", {
250+
title: "Creating Database...",
251+
size: 100,
252+
});
250253
aboutCodeDB.db
251-
.then(() => progress.show())
252-
.then(() => aboutCodeDB.addFromJson(jsonFileName, aboutCodeVersion))
253-
.then(() => progress.hide())
254+
.then(() => progressbar.showDeterminate())
255+
.then(() => aboutCodeDB.addFromJson(
256+
jsonFileName,
257+
aboutCodeVersion,
258+
progress => progressbar.update(progress/100)))
259+
.then(() => progressbar.hide())
254260
.then(() => loadDataForViews(fileName))
255261
.catch((err) => {
256-
progress.hide();
262+
progressbar.hide();
257263
if (err instanceof MissingFileInfoError) {
258264
dialog.showErrorBox(
259265
"Missing File Type Information",
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
about_resource: progressbar.min.js
2+
download_url: https://github.com/kimmobrunfeldt/progressbar.js/blob/acbe78ba5c341ea9432fb11dfd7464d7ec669c06/dist/progressbar.min.js
3+
version: acbe78b
4+
5+
name: ProgressBar.js
6+
description: Responsive and slick progress bars with animated SVG paths
7+
home_url: https://kimmobrunfeldt.github.io/progressbar.js/
8+
owner: Kimmo Brunfeldt
9+
dje_license: mit
10+
license_text_file: progressbar.LICENSE
11+
copyright: Copyright (c) 2015 Kimmo Brunfeldt
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 Kimmo Brunfeldt
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

0 commit comments

Comments
 (0)