Skip to content

Commit

Permalink
Merge pull request #206 from HFragnaud/master
Browse files Browse the repository at this point in the history
Datahandler fixed and some others, see details
  • Loading branch information
HFragnaud authored Jun 8, 2018
2 parents e58f1a1 + 233e348 commit 8b4e454
Show file tree
Hide file tree
Showing 18 changed files with 78 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,10 @@ def is_authorised(request, collab_id):
if request.META.get("HTTP_AUTHORIZATION", None) == None :
return False
else:
auth = _is_collaborator_token(request, collab_id)
auth = _is_collaborator_token(request, admin_id)
return auth
if not (_is_collaborator_token(request, collab_id) or _is_collaborator_token(request, collab_id)):
return False
else:
return True

else :
if not (_is_collaborator(request, collab_id) or _is_collaborator(request,admin_id)):
Expand Down
4 changes: 3 additions & 1 deletion model_validation_api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1209,7 +1209,9 @@ def put(self, request, format=None):
## save only modifications on model. if you want to modify images or instances, do separate put.
##get objects
value = request.data['models'][0]

app_id = request.GET.getlist('app_id')

if len(app_id) > 0 :
value['app_id'] = app_id[0]

Expand All @@ -1230,7 +1232,7 @@ def put(self, request, format=None):
return HttpResponse('Unauthorized', status=401)
return HttpResponseForbidden()

app_id = value['app_id']
app_id = value['app']['id']

collab_id = get_collab_id_from_app_id(app_id)
if not is_authorised(request, collab_id):
Expand Down
57 changes: 19 additions & 38 deletions validation_service/app/js/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,12 @@ testApp.controller('HomeCtrl', ['$scope', '$rootScope', '$http', '$location', "S
$scope.tests = [];
$scope.total_models = 0;

$scope._load_other_models = function() {
var i = 2;
for (i; i <= $scope.nb_pages; i++) {
DataHandler.loadModelsByPage({ app_id: $scope.app_id, page: i }).then(function(new_models) {
$scope.models.models = $scope.models.models.concat(new_models.models);
$scope.models.models = $scope.models.models.sort(_sort_array_by_timestamp_desc)
$scope.$apply();
})
}
}
var _sort_array_by_timestamp_desc = function(a, b) {
return new Date(b.creation_date) - new Date(a.creation_date);
}
$scope.$on('models_updated', function(event, models) {
$scope.models = models;
});


Context.setService().then(function() {
console.log('collab parameters setted')

$scope.Context = Context;
$scope.ctx = Context.getCtx();
Expand All @@ -43,10 +34,7 @@ testApp.controller('HomeCtrl', ['$scope', '$rootScope', '$http', '$location', "S
$scope.collab_data_modalities = CollabParameters.getParametersOrDefaultByType("data_modalities");
$scope.collab_organization = CollabParameters.getParametersOrDefaultByType("organization");

//$scope.models = ScientificModelRest.get({ app_id: app_id }, function(data) {});
//$scope.tests = ValidationTestDefinitionRest.get({ app_id: app_id }, function(data) {});
// //for test
// $scope.put_test1 = ValidationTestCodeRest.put({ app_id: app_id, test_definition_id: "53a7a2db-b18f-49ef-b1de-88bd48960c81", version: "1.1" });

DataHandler.loadModels({ app_id: $scope.app_id, page: 1 }).then(function(data) {
$scope.total_models = data.total_models;
$scope.nb_pages = data.total_nb_pages;
Expand All @@ -59,7 +47,11 @@ testApp.controller('HomeCtrl', ['$scope', '$rootScope', '$http', '$location', "S
$('#preloader-models').delay(350).fadeOut('slow'); // will fade out the white DIV that covers the website.
$('#models-panel').delay(350).css({ 'overflow': 'visible' });

$scope._load_other_models();

var status = DataHandler.getCurrentStatus();
if (status != "up_to_date") {
DataHandler.loadModelsByPage($scope.app_id, $scope.nb_pages);
}
});

DataHandler.loadTests({ app_id: $scope.app_id }).then(function(data) {
Expand Down Expand Up @@ -1126,21 +1118,9 @@ ModelCatalogApp.controller('ModelCatalogCtrl', [
return models
}


$scope._load_other_models = function() {
var i = 2;
for (i; i <= $scope.nb_pages; i++) {
DataHandler.loadModelsByPage({ app_id: $scope.app_id, page: i }).then(function(new_models) {
$scope.models.models = $scope.models.models.concat($scope._change_empty_organization_string(new_models).models);
$scope.models.models = $scope.models.models.sort(_sort_array_by_timestamp_desc)
$scope.$apply();
})
}
}

var _sort_array_by_timestamp_desc = function(a, b) {
return new Date(b.creation_date) - new Date(a.creation_date);
}
$scope.$on('models_updated', function(event, models) {
$scope.models = $scope._change_empty_organization_string(models);
});

Context.setService().then(function() {

Expand All @@ -1166,11 +1146,12 @@ ModelCatalogApp.controller('ModelCatalogCtrl', [
$('#preloader').delay(350).fadeOut('slow'); // will fade out the white DIV that covers the website.
$('body').delay(350).css({ 'overflow': 'visible' });


$scope._load_other_models();


var status = DataHandler.getCurrentStatus();
if (status != "up_to_date") {
DataHandler.loadModelsByPage($scope.app_id, $scope.nb_pages);
}
});

Context.sendState("model", "n");


Expand Down
60 changes: 38 additions & 22 deletions validation_service/app/js/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -440,41 +440,52 @@ DataHandlerServices.service('DataHandler', ['$rootScope', 'ScientificModelRest',
var temp_models = ScientificModelRest.get(dict_params);
temp_models.$promise.then(function() {
models = { date_last_load: new Date(), status: "loading", data: temp_models };
resolve(models.data);
resolve(models.data, models.status);
});

} else {
if (models.status == "up to date") {
if (models.status == "up_to_date") {
var data = _loadStoredModels();
resolve(data);
resolve(data, models.status);
} else {
var temp_models = ScientificModelRest.get(dict_params);
temp_models.$promise.then(function() {
if (temp_models.total_nb_pages == dict_params.page) {
models = { date_last_load: new Date(), status: "loading", data: temp_models };
} else {
models = { date_last_load: new Date(), status: "up_to_date", data: temp_models };
}
resolve(models.data);
models = { date_last_load: new Date(), status: "up_to_date", data: temp_models };
resolve(models.data, models.status);
});
}
}
});
};

var loadModelsByPage = function(dict_params) {
return new Promise(function(resolve, reject) {
var temp_models = ScientificModelRest.get(dict_params);
//var temp_models = _get_models_sequentially(dict_params);
temp_models.$promise.then(function() {
if (temp_models.total_nb_pages == dict_params.page) {
models = { date_last_load: new Date(), status: "loading", data: temp_models };
} else {
models = { date_last_load: new Date(), status: "up_to_date", data: temp_models };
}
resolve(models.data);
});
})
var loadModelsByPage = function(app_id, nb_pages) {
var i = 1;
var pages_loaded = new Array();
pages_loaded.push(1);

for (i; i <= nb_pages; i++) {
if (pages_loaded.indexOf(i) == -1) {
pages_loaded.push(i);
ScientificModelRest.get({ app_id: app_id, page: i }).$promise.then(function(new_models) {
models.data.models = models.data.models.concat(new_models.models);
models.data.models = models.data.models.sort(_sort_array_by_timestamp_desc)

//fire event to update models
$rootScope.$broadcast('models_updated', models.data);

//change status if last load is done
if (pages_loaded.length == nb_pages.length) {
models.date_last_load = new Date();
models.status = "up_to_date";
}
})
}

}
}

var _sort_array_by_timestamp_desc = function(a, b) {
return new Date(b.creation_date) - new Date(a.creation_date);
}
var _get_models_sequentially = function(dict_params) {
//load 50 first elements should return also the number of pages
Expand Down Expand Up @@ -545,15 +556,20 @@ DataHandlerServices.service('DataHandler', ['$rootScope', 'ScientificModelRest',
var getStoredTests = function() {
return tests;
}
var getCurrentStatus = function() {
return models.status
}

return {
loadModels: loadModels,
loadModelsByPage: loadModelsByPage,
loadTests: loadTests,
getStoredModels: getStoredModels,
getStoredTests: getStoredTests,
getCurrentStatus: getCurrentStatus,
setStoredModelsAsOutdated: setStoredModelsAsOutdated,
setStoredTestsAsOutdated: setStoredTestsAsOutdated,

};

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<html id="model-create" ng-controller="ModelCatalogCreateCtrl">
<html id="model-create">

<head>
<nav class="navbar ">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<html id="model-detail" ng-controller="ModelCatalogDetailCtrl">
<html id="model-detail">

<head>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<html id="model-edit" ng-controller="ModelCatalogEditCtrl">
<html id="model-edit">

<form>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<html id="model-version" ng-controller="ModelCatalogVersionCtrl">
<html id="model-version">

<head>
<nav class="navbar ">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<html id="model-list" ng-controller="ModelCatalogCtrl">
<html id="model-list">

<body>
<nav class="navbar ">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<html id="model-help" ng-controller="ModelCatalogHelpPage">
<html id="model-help">

<nav class="navbar">
<br>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div ng-controller="HomeCtrl">
<div>

<nav class="navbar">
<br>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ <h1>



<div ng-controller="TestResultCtrl">
<div>

<nvd3 options='options5' data='data5' id='chart svg'></nvd3>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<html id="validation-help" ng-controller="ValHelpCtrl">
<html id="validation-help">
<nav class="navbar">
<br>
<button class="button-MC" ng-click="Context.validation_goToHomeView();"> Home</button>&ensp;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<html id="model-detail" ng-controller="ValModelDetailCtrl">
<html id="model-detail">

<body>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<html id="model-list" ng-controller="ValTestCtrl">
<html id="model-list">
<nav class="navbar">
<br>
<button class="button-MC" ng-click="Context.validation_goToHomeView();">Home</button>&ensp;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div ng-controller="ValTestCreateCtrl">
<div>
<nav class="navbar">
<br>
<button class="button-MC" ng-click="Context.validation_goToHomeView();">Home</button>&ensp;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div ng-controller="ValTestDetailCtrl">
<div>

<head>
<nav class="navbar">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<html id="test-result-detail" ng-controller="ValTestResultDetailCtrl">
<html id="test-result-detail">

<head>
<nav class="navbar ">
Expand Down

0 comments on commit 8b4e454

Please sign in to comment.