Skip to content

Progress bar - use remaining percentage time #169

Open
@polomarcus

Description

@polomarcus

For http://siddii.github.io/angular-timer/index.html#/progressbar-timer

Enable users to access to the attribute displayProgressBar that will represent the remaining percentage (0 to 100) between the countdown beginning and the countdown ending.

 //progress bar
    $scope.displayProgressBar = 0;
    $scope.displayProgressActive = 'active'; //css class none or active

/**
     * calculate the remaining time in a progress bar in percentage
     * @param {float} initCountdown
     * @param {moment} currentCountdown
     * @param {moment} alarmTime
     *
     * @return {float} 0 --> 100
     */
    function calculateProgressBar(initCountdown, currentCountdown, alarmTime ) {
      var displayProgressBar;

      displayProgressBar = alarmTime.diff(currentCountdown, 'seconds') * 100 / initCountdown ;
      displayProgressBar = 100 - displayProgressBar;

      displayProgressBar = Math.round(displayProgressBar * 10) / 10;

      if(displayProgressBar > 100){
        displayProgressBar = 100;
      }

      return displayProgressBar;
    }

Usage example

<div class="progress">
                        <div class="progress-bar progress-bar-success progress-bar-striped {{displayProgressActive}}" role="progressbar" aria-valuenow="{{ displayProgressBar }}" aria-valuemin="0" aria-valuemax="100" style="min-width: 2.3em; width:{{ displayProgressBar }}%;">
                            {{ displayProgressBar }}%
                        </div>
                    </div>

PR coming soon

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions