Skip to content
Snippets Groups Projects
Select Git revision
  • 1d41394759c6eb18268dc22cfc9cee9dabaeef6f
  • master default protected
  • chrome-manifest-v3
  • feature/migrate-cordova-13
  • feat/improve-network-scan
  • feat/force-migration-check
  • develop
  • feature/encrypted_comment
  • feature/android_api_19
  • gitlab_migration_1
  • rml8
  • v1.7.15-rc1
  • v1.7.14
  • v1.7.13
  • v1.7.12
  • v1.7.11
  • v1.7.10
  • v1.7.9
  • v1.7.8
  • v1.7.7
  • v1.7.6
  • v1.7.5
  • v1.7.4
  • v1.7.3
  • v1.7.2
  • v1.7.1
  • v1.7.0
  • v1.7.0-rc2
  • v1.7.0-rc1
  • v1.6.12
  • v1.6.11
31 results

common-controllers.js

Blame
  • common-controllers.js 12.65 KiB
    
    angular.module('cesium.graph.common.controllers', ['cesium.services'])
    
      .controller('GpCurrencyAbstractCtrl', GpCurrencyAbstractController)
    ;
    
    function GpCurrencyAbstractController($scope, $filter, $ionicPopover, $ionicHistory, $state, csSettings, csCurrency, esHttp, UIUtils) {
      'ngInject';
    
      $scope.loading = true;
      $scope.formData = $scope.formData || {
        useRelative: csSettings.data.useRelative,
        timePct: 100,
        rangeDuration: 'day',
        maxAge: undefined, // forever
        firstBlockTime: 0,
        scale: 'linear',
        hide: [],
        beginAtZero: true
      };
      $scope.scale = 'linear';
      $scope.height = undefined;
      $scope.width = undefined;
      $scope.maintainAspectRatio = true;
      $scope.times = [];
    
      function _truncDate(time) {
        return moment.unix(time).utc().startOf($scope.formData.rangeDuration).unix();
      }
    
      $scope.enter = function (e, state) {
        if ($scope.loading) {
    
          // Make sure there is currency, or load it not
          if (!$scope.formData.currency) {
            return csCurrency.get()
              .then(function (currency) {
                $scope.formData.currency = currency ? currency.name : null;
                $scope.formData.firstBlockTime = currency ? _truncDate(currency.firstBlockTime) : 0;
                if (!$scope.formData.firstBlockTime){
                  console.warn('[graph] currency.firstBlockTime not loaded ! Should have been loaded by currrency service!');
                }
                $scope.formData.currencyAge = _truncDate(moment().utc().unix()) - $scope.formData.firstBlockTime;
    
                return $scope.enter(e, state); // Loop
              });
          }
    
          if (state && state.stateParams) {
            // remember state, to be able to refresh location
            $scope.stateName = state && state.stateName;
            $scope.stateParams = angular.copy(state && state.stateParams||{});
    
            if (!$scope.formData.currency && state && state.stateParams && state.stateParams.currency) { // Currency parameter
              $scope.formData.currency = state.stateParams.currency;
            }
            if (state.stateParams.t) {
              $scope.formData.timePct = state.stateParams.t;
            }
            else if (state.stateParams.timePct) {
              $scope.formData.timePct = state.stateParams.timePct;
            }
            if (state.stateParams.stepUnit) {
              $scope.formData.rangeDuration = state.stateParams.stepUnit;
            }
            if (state.stateParams.scale) {
              $scope.formData.scale = state.stateParams.scale;
            }
            // Allow to hide some dataset
            if (state.stateParams.hide) {