Skip to content

Commit

Permalink
step 2. removed all GET /tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
edospadoni committed Nov 21, 2023
1 parent a8863d0 commit b5cf495
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 195 deletions.
45 changes: 4 additions & 41 deletions wizard/app/scripts/controllers/configurations/devices.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ angular.module('nethvoiceWizardUiApp')
$scope.allModels = {};
$scope.networks = {};
$scope.networkLength = 0;
$scope.tasks = {};
$scope.scanned = false;

$scope.orderByValue = function (value) {
Expand All @@ -33,7 +32,6 @@ angular.module('nethvoiceWizardUiApp')
ConfigService.getNetworks().then(function (res) {
$scope.networks = res.data;
for (var eth in res.data) {
$scope.tasks[eth] = {};
$scope.allDevices[eth] = {};
}
$scope.networkLength = Object.keys(res.data).length;
Expand All @@ -47,59 +45,24 @@ angular.module('nethvoiceWizardUiApp')
$scope.getPhoneList = function (key, network, callback) {
DeviceService.phoneListByNetwork(network).then(function (res) {
$scope.allDevices[key] = res.data;
$scope.tasks[key].currentProgress = 100;
$scope.scanned = true;
callback(null);
}, function (err) {
if (err.status !== 404) {
$scope.tasks[key].currentProgress = -1;
} else {
$scope.tasks[key].currentProgress = 100;
}
callback(err);
});
};

$scope.startScan = function (key, network) {
if ($scope.tasks[key].currentProgress > 0 && $scope.tasks[key].currentProgress < 100) {
return true;
}
$scope.tasks[key].startScan = true;
$scope.tasks[key].currentProgress = Math.floor((Math.random() * 50) + 10);
DeviceService.startScan(network).then(function (res) {
$scope.tasks[key].promise = $interval(function () {
UtilService.taskStatus(res.data.result).then(function (res) {
if (res.data.progress < 100) {
$scope.errorCount = 0;
} else if (res.data.progress == 100) {
$scope.tasks[key].errorCount = 0;
$interval.cancel($scope.tasks[key].promise);
$scope.getPhoneList(key, network, function (err) {
if (err) {
console.log(err);
}
});
} else {
console.log(res.error);
if ($scope.tasks[key].errorCount < appConfig.MAX_TRIES) {
$scope.tasks[key].errorCount++;
} else {
$interval.cancel($scope.tasks[key].promise);
$scope.tasks[key].currentProgress = -1;
}
}
}, function (err) {
$scope.getPhoneList(key, network, function (err) {
if (err) {
console.log(err);
if ($scope.tasks[key].errorCount < appConfig.MAX_TRIES) {
$scope.tasks[key].errorCount++;
} else {
$interval.cancel($scope.tasks[key].promise);
$scope.tasks[key].currentProgress = -1;
}
});
}, appConfig.INTERVAL_POLLING);
}
});
}, function (err) {
$scope.tasks[key].currentProgress = -1;
console.log(err);
});
};
Expand Down
43 changes: 1 addition & 42 deletions wizard/app/scripts/controllers/devices/inventory.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ angular.module('nethvoiceWizardUiApp')
.controller('DevicesInventoryCtrl', function ($scope, $rootScope, $interval, $q, $timeout, PhoneService, ModelService, UtilService, ConfigService, DeviceService, LocalStorageService, UserService) {
$scope.phones = [];
$scope.models = [];
$scope.tasks = {};
$scope.networkScanInProgress = false;
$scope.view.changeRoute = true;
$scope.pastedMacs = [];
Expand Down Expand Up @@ -73,10 +72,6 @@ angular.module('nethvoiceWizardUiApp')
network.name = networkName;
});
$scope.networks = networks;

for (var eth in $scope.networks) {
$scope.tasks[eth] = {};
}
}

function gotDefaults(defaults) {
Expand Down Expand Up @@ -281,43 +276,11 @@ angular.module('nethvoiceWizardUiApp')
// start scan
$scope.phonesToAdd = [];
$scope.networkScanInProgress = true;
$scope.tasks[netName].currentProgress = Math.floor((Math.random() * 50) + 10);
DeviceService.startScan($scope.networkToScan).then(function (res) {
$scope.tasks[netName].promise = $interval(function () {
UtilService.taskStatus(res.data.result).then(function (res) {
if (res.data.progress < 100) {
$scope.tasks[netName].currentProgress = res.data.progress;
$scope.tasks[netName].errorCount = 0;
} else if (res.data.progress == 100) {
$scope.tasks[netName].currentProgress = res.data.progress;
$scope.tasks[netName].errorCount = 0;
$interval.cancel($scope.tasks[netName].promise);
networkScanCompleted($scope.networkToScan);
} else {
console.log(res.error);
if ($scope.tasks[netName].errorCount < appConfig.MAX_TRIES) {
$scope.tasks[netName].errorCount++;
} else {
$interval.cancel($scope.tasks[netName].promise);
$scope.networkScanInProgress = false;
$scope.tasks[netName].currentProgress = -1;
}
}
}, function (err) {
console.log(err);
if ($scope.tasks[netName].errorCount < appConfig.MAX_TRIES) {
$scope.tasks[netName].errorCount++;
} else {
$interval.cancel($scope.tasks[netName].promise);
$scope.networkScanInProgress = false;
$scope.tasks[netName].currentProgress = -1;
}
});
}, appConfig.INTERVAL_POLLING);
networkScanCompleted($scope.networkToScan);
}, function (err) {
console.log(err);
addErrorNotification(err.data, "Error scanning network");
$scope.tasks[netName].currentProgress = -1;
});
}

Expand Down Expand Up @@ -364,10 +327,6 @@ angular.module('nethvoiceWizardUiApp')
}

$scope.cancelAllNetworkScans = function (netName) {
for (var netName in $scope.tasks) {
$interval.cancel($scope.tasks[netName].promise);
$scope.networkScanInProgress = false;
}
}

$scope.clearValidationErrorsManual = function () {
Expand Down
38 changes: 1 addition & 37 deletions wizard/app/scripts/controllers/trunks/physical.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ angular.module('nethvoiceWizardUiApp')
$scope.allModels = {};
$scope.networks = {};
$scope.networkLength = 0;
$scope.tasks = {};
$scope.sipTrunks = {};
$scope.selectedDevice = {};
$scope.newGateway = {};
Expand Down Expand Up @@ -99,7 +98,6 @@ angular.module('nethvoiceWizardUiApp')
ConfigService.getNetworks().then(function (res) {
$scope.networks = res.data;
for (var eth in res.data) {
$scope.tasks[eth] = {};
$scope.allDevices[eth] = [];
}
$scope.networkLength = Object.keys(res.data).length;
Expand All @@ -114,12 +112,10 @@ angular.module('nethvoiceWizardUiApp')
DeviceService.gatewayListByNetwork(network).then(function (res) {
$scope.allDevices[key] = res.data;
$scope.pushKey(key);
$scope.tasks[key].currentProgress = 100;
$scope.onSave = false;
$scope.scanned = true;
}, function (err) {
console.log(err);
$scope.tasks[key].currentProgress = -1;
});
};

Expand All @@ -136,41 +132,9 @@ angular.module('nethvoiceWizardUiApp')
}

$scope.startScan = function (key, network) {
if ($scope.tasks[key].currentProgress > 0 && $scope.tasks[key].currentProgress < 100) {
return true;
}
$scope.tasks[key].startScan = true;
$scope.tasks[key].currentProgress = Math.floor((Math.random() * 50) + 10);
DeviceService.startScan(network).then(function (res) {
$scope.tasks[key].promise = $interval(function () {
UtilService.taskStatus(res.data.result).then(function (res) {
if (res.data.progress < 100) {
$scope.errorCount = 0;
} else if (res.data.progress == 100) {
$scope.tasks[key].errorCount = 0;
$interval.cancel($scope.tasks[key].promise);
$scope.getGatewayList(key, network);
} else {
console.log(res.error);
if ($scope.tasks[key].errorCount < appConfig.MAX_TRIES) {
$scope.tasks[key].errorCount++;
} else {
$interval.cancel($scope.tasks[key].promise);
$scope.tasks[key].currentProgress = -1;
}
}
}, function (err) {
console.log(err);
if ($scope.tasks[key].errorCount < appConfig.MAX_TRIES) {
$scope.tasks[key].errorCount++;
} else {
$interval.cancel($scope.tasks[key].promise);
$scope.tasks[key].currentProgress = -1;
}
});
}, appConfig.INTERVAL_POLLING);
$scope.getGatewayList(key, network);
}, function (err) {
$scope.tasks[key].currentProgress = -1;
console.log(err);
});
};
Expand Down
47 changes: 7 additions & 40 deletions wizard/app/scripts/controllers/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ angular.module('nethvoiceWizardUiApp')
$scope.startInstall = false;
$scope.currentProgress = 0;
$scope.selectedMode = '';
$scope.taskPromise = null;
$scope.errorCount = 0;

$scope.nextStepUsers = function () {
Expand Down Expand Up @@ -49,10 +48,6 @@ angular.module('nethvoiceWizardUiApp')
});
}

$scope.$on('$destroy', function () {
$interval.cancel($scope.taskPromise);
});

$scope.goNethserverSssdConfig = function () {
window.location.href = window.location.origin + ":9090/nethserver#/users-groups";
};
Expand All @@ -65,44 +60,16 @@ angular.module('nethvoiceWizardUiApp')
ConfigService.setConfig(mode).then(function (res) {
if (mode === 'legacy') {
$('#uc-button').addClass('disabled');
$scope.taskPromise = $interval(function () {
UtilService.taskStatus(res.data.result).then(function (res) {
if (res.data.progress < 100) {
$scope.errorCount = 0;
$scope.currentProgress = res.data.progress;
} else if (res.data.progress == 100) {
$scope.errorCount = 0;
$interval.cancel($scope.taskPromise);
$scope.currentProgress = 100;
$scope.mode.isLdap = true;
$scope.errorCount = 0;
$scope.mode.isLdap = true;

if ($scope.wizard.isMigration) {
$scope.wizard.isMigrationView = true;
$scope.wizard.isWizard = false;
$location.path('/migration');
}
} else {
console.log(res.error);
if ($scope.errorCount < appConfig.MAX_TRIES) {
$scope.errorCount++;
} else {
$interval.cancel($scope.taskPromise);
$scope.currentProgress = -1;
}
}
}, function (err) {
console.log(err);
if ($scope.errorCount < appConfig.MAX_TRIES) {
$scope.errorCount++;
} else {
$interval.cancel($scope.taskPromise);
$scope.currentProgress = -1;
}
});
}, 5000);
if ($scope.wizard.isMigration) {
$scope.wizard.isMigrationView = true;
$scope.wizard.isWizard = false;
$location.path('/migration');
}
} else {
$('#legacy-button').addClass('disabled');
$scope.currentProgress = 100;
}
}, function (err) {
console.log(err);
Expand Down
10 changes: 0 additions & 10 deletions wizard/app/scripts/services/utilservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,6 @@ angular.module('nethvoiceWizardUiApp')
return text;
};

this.taskStatus = function (task) {
return $q(function (resolve, reject) {
RestService.get('/tasks/' + task).then(function (res) {
resolve(res);
}, function (err) {
reject(err);
});
});
};

this.maskToCidr = function (obj) {
if (obj === undefined) {
return '';
Expand Down
12 changes: 0 additions & 12 deletions wizard/app/views/configurations/devices.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,6 @@ <h2 class="card-pf-title text-center">
<span class="inline-display" popover-placement="top" popover-trigger="'mouseenter'" popover-animation="true" uib-popover="{{'Netmask' | translate}}: {{network.netmask}}"><input ng-model="network.netmask" type="text" class="form-control config-form"></span>
</div>
</div>
<p class="card-pf-info text-center">
<div class="blank-slate-pf-main-action centered adjust-bottom">
<button ng-click="startScan(key, network)" class="btn btn-primary btn-lg {{tasks[key].currentProgress > 0 && tasks[key].currentProgress < 100 ? 'disabled' : ''}}">{{'Scan' | translate}}</button>
<div ng-if="tasks[key].currentProgress < 100 && tasks[key].currentProgress != -1" class="spinner spinner-sm spinner-inline spinner-right absolute-icon-right"></div>
<div ng-if="tasks[key].currentProgress == 100 || tasks[key].currentProgress == -1" class="pficon pficon-{{tasks[key].currentProgress == 100 ? 'ok' : 'error-circle-o'}} icon-right absolute-icon-right"></div>
</div>
<div ng-if="tasks[key].startScan" class="progress">
<div class="progress-bar {{tasks[key].currentProgress == -1 ? 'progress-bar-danger' : 'progress-bar-success'}}" role="progressbar" aria-valuemin="0" aria-valuemax="100" style="width: {{tasks[key].currentProgress == -1 ? '100' : tasks[key].currentProgress}}%;">
<span>{{tasks[key].currentProgress == -1 ? '100' : tasks[key].currentProgress}}%</span>
</div>
</div>
</p>
</div>
</div>
</div>
Expand Down
13 changes: 0 additions & 13 deletions wizard/app/views/trunks/physical.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,6 @@ <h2 class="card-pf-title text-center">
<span class="inline-display" popover-placement="top" popover-trigger="'mouseenter'" popover-animation="true" uib-popover="{{'Netmask' | translate}}: {{network.netmask}}"><input ng-model="network.netmask" type="text" class="form-control config-form"></span>
</div>
</div>
<p class="card-pf-info text-center">
<div class="blank-slate-pf-main-action centered adjust-bottom">
<button ng-click="startScan(key, network)" class="btn btn-primary btn-lg {{tasks[key].currentProgress > 0 && tasks[key].currentProgress < 100 ? 'disabled' : ''}}">{{'Scan' | translate}}</button>
<button ng-disabled="selectedDevice.onSave" ng-click="setNewGateway(key, networks[key])" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#newGwDialog">{{'Add gateway' | translate}}</button>
<div ng-if="tasks[key].currentProgress < 100 && tasks[key].currentProgress != -1" class="spinner spinner-sm spinner-inline spinner-right absolute-icon-right"></div>
<div ng-if="tasks[key].currentProgress == 100 || tasks[key].currentProgress == -1" class="pficon pficon-{{tasks[key].currentProgress == 100 ? 'ok' : 'error-circle-o'}} icon-right absolute-icon-right"></div>
</div>
<div ng-if="tasks[key].startScan" class="progress">
<div class="progress-bar {{tasks[key].currentProgress == -1 ? 'progress-bar-danger' : 'progress-bar-success'}}" role="progressbar" aria-valuemin="0" aria-valuemax="100" style="width: {{tasks[key].currentProgress == -1 ? '100' : tasks[key].currentProgress}}%;">
<span>{{tasks[key].currentProgress == -1 ? '100' : tasks[key].currentProgress}}%</span>
</div>
</div>
</p>
</div>
</div>
</div>
Expand Down

0 comments on commit b5cf495

Please sign in to comment.