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.
1616
1717class 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
5584module . exports = Progress ;
0 commit comments