From 0219716b8211fef9dd430706c0a8a5581045c053 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bjo=CC=88rn=20Dahlgren?= Date: Thu, 1 Feb 2018 01:11:31 +0100 Subject: [PATCH] AAR integration --- src/app/routes/operations/edit_operation.html | 1 + src/app/routes/operations/operation.html | 2 + src/index.js | 5 ++ src/operations/controllers/aar_controller.js | 23 ++++++++ .../controllers/aar_search_controller.js | 31 ++++++++++ .../controllers/edit_aar_controller.js | 59 +++++++++++++++++++ src/operations/directives/aar_controller.js | 9 +++ .../directives/edit_aar_controller.js | 9 +++ src/operations/services/aar.js | 31 ++++++++++ src/operations/templates/aar_controller.html | 19 ++++++ src/operations/templates/aar_search.html | 43 ++++++++++++++ .../templates/edit_aar_controller.html | 24 ++++++++ 12 files changed, 256 insertions(+) create mode 100644 src/operations/controllers/aar_controller.js create mode 100644 src/operations/controllers/aar_search_controller.js create mode 100644 src/operations/controllers/edit_aar_controller.js create mode 100644 src/operations/directives/aar_controller.js create mode 100644 src/operations/directives/edit_aar_controller.js create mode 100644 src/operations/services/aar.js create mode 100644 src/operations/templates/aar_controller.html create mode 100644 src/operations/templates/aar_search.html create mode 100644 src/operations/templates/edit_aar_controller.html diff --git a/src/app/routes/operations/edit_operation.html b/src/app/routes/operations/edit_operation.html index d8979b1..4279b2e 100644 --- a/src/app/routes/operations/edit_operation.html +++ b/src/app/routes/operations/edit_operation.html @@ -2,6 +2,7 @@
+ diff --git a/src/app/routes/operations/operation.html b/src/app/routes/operations/operation.html index 1644933..686f499 100644 --- a/src/app/routes/operations/operation.html +++ b/src/app/routes/operations/operation.html @@ -9,6 +9,8 @@
+ + diff --git a/src/index.js b/src/index.js index 97e14f4..4cf8251 100644 --- a/src/index.js +++ b/src/index.js @@ -15,6 +15,7 @@ var app = angular.module('app', [ app.constant('ApiConfig', { BASE_API: 'https://api.anrop.se', + BASE_AAR_API: 'https://api.aar.anrop.se', BASE_ARMA3SYNC_API: 'https://arma3sync.anrop.se/manager/api', BASE_PWS_API: 'https://playwithsix.anrop.se', BASE_STEAM_WORKSHOP_API: 'https://steam-workshop.anrop.se', @@ -25,6 +26,10 @@ app.constant('ImgurConfig', { API_KEY: 'Client-ID c068f0d04c394eb' }) +app.constant('WebConfig', { + BASE_AAR_WEB: 'https://aar.anrop.se' +}) + app.config(function ($locationProvider, $routeProvider) { $locationProvider.html5Mode(true) $routeProvider diff --git a/src/operations/controllers/aar_controller.js b/src/operations/controllers/aar_controller.js new file mode 100644 index 0000000..939d622 --- /dev/null +++ b/src/operations/controllers/aar_controller.js @@ -0,0 +1,23 @@ +angular.module('operations').controller('AARCtrl', function ($scope, WebConfig, AARSvc) { + $scope.aarUrl = function (aar) { + return WebConfig.BASE_AAR_WEB + '/missions/' + aar.aar_id + } + + $scope.load = function () { + AARSvc.operation($scope.operationId).then(function (aars) { + aars.forEach(function (aar) { + AARSvc.mission(aar.aar_id).then(function (info) { + Object.assign(aar, { + length: info.length, + name: info.name, + world: info.world + }) + }) + }) + + $scope.aars = aars + }) + } + + $scope.load() +}) diff --git a/src/operations/controllers/aar_search_controller.js b/src/operations/controllers/aar_search_controller.js new file mode 100644 index 0000000..36a8e2c --- /dev/null +++ b/src/operations/controllers/aar_search_controller.js @@ -0,0 +1,31 @@ +angular.module('operations').controller('AARSearchCtrl', function ($scope, $uibModalInstance, WebConfig, AARSvc) { + $scope.aars = [] + $scope.loading = false + + $scope.aarUrl = function (aar) { + return WebConfig.BASE_AAR_WEB + '/missions/' + aar.id + } + + $scope.load = function (query) { + $scope.aars = [] + $scope.loading = true + AARSvc.missions().then(function (aars) { + var operationDate = new Date($scope.operation.start) + $scope.aars = aars.filter(function (aar) { + var aarDate = new Date(aar.created_at) + return ( + aarDate.getFullYear() === operationDate.getFullYear() && + aarDate.getMonth() === operationDate.getMonth() && + aarDate.getDate() === operationDate.getDate() + ) + }) + $scope.loading = false + }) + } + + $scope.close = function () { + $uibModalInstance.dismiss('cancel') + } + + $scope.load() +}) diff --git a/src/operations/controllers/edit_aar_controller.js b/src/operations/controllers/edit_aar_controller.js new file mode 100644 index 0000000..cb4a48b --- /dev/null +++ b/src/operations/controllers/edit_aar_controller.js @@ -0,0 +1,59 @@ +angular.module('operations').controller('EditAARCtrl', function ($scope, $uibModal, WebConfig, AARSvc, OperationSvc) { + $scope.add = function (data) { + var found = $scope.aars.filter(function (aar) { + return aar.aar_id === data.id + }) + + if (found.length === 0) { + return AARSvc.add($scope.operationId, { aar_id: data.id }).then(function () { + loadAARs() + return this + }) + } + } + + $scope.aarUrl = function (aar) { + return WebConfig.BASE_AAR_WEB + '/missions/' + aar.aar_id + } + + $scope.delete = function (aar) { + AARSvc.delete($scope.operationId, aar.id).then(function () { + loadAARs() + return this + }) + } + + $scope.search = function () { + $uibModal.open({ + template: require('../templates/aar_search.html'), + controller: 'AARSearchCtrl', + scope: $scope + }).result.then(function () { + + }, function () { + + }) + } + + var loadAARs = function () { + OperationSvc.operation($scope.operationId).then(function (operation) { + $scope.operation = operation + }) + + AARSvc.operation($scope.operationId).then(function (aars) { + aars.forEach(function (aar) { + AARSvc.mission(aar.aar_id).then(function (info) { + Object.assign(aar, { + length: info.length, + name: info.name, + world: info.world + }) + }) + }) + + $scope.aars = aars + }) + } + + loadAARs() +}) diff --git a/src/operations/directives/aar_controller.js b/src/operations/directives/aar_controller.js new file mode 100644 index 0000000..70c8682 --- /dev/null +++ b/src/operations/directives/aar_controller.js @@ -0,0 +1,9 @@ +angular.module('operations').directive('aarController', function () { + return { + controller: 'AARCtrl', + scope: { + operationId: '=' + }, + template: require('../templates/aar_controller.html') + } +}) diff --git a/src/operations/directives/edit_aar_controller.js b/src/operations/directives/edit_aar_controller.js new file mode 100644 index 0000000..5663458 --- /dev/null +++ b/src/operations/directives/edit_aar_controller.js @@ -0,0 +1,9 @@ +angular.module('operations').directive('editAarController', function () { + return { + controller: 'EditAARCtrl', + scope: { + operationId: '=' + }, + template: require('../templates/edit_aar_controller.html') + } +}) diff --git a/src/operations/services/aar.js b/src/operations/services/aar.js new file mode 100644 index 0000000..7f753ae --- /dev/null +++ b/src/operations/services/aar.js @@ -0,0 +1,31 @@ +angular.module('operations').factory('AARSvc', function ($http, ApiConfig) { + return { + missions: function () { + return $http.get(ApiConfig.BASE_AAR_API + '/missions').then(function (response) { + return response.data + }) + }, + mission: function (id) { + return $http.get(ApiConfig.BASE_AAR_API + '/missions/' + id).then(function (response) { + return response.data + }) + }, + operation: function (operationId) { + return $http.get(ApiConfig.BASE_API + '/operations/' + operationId + '/aar').then(function (response) { + return response.data + }) + }, + add: function (operationId, data) { + return $http.post(ApiConfig.BASE_API + '/operations/' + operationId + '/aar', { + aar: data + }).then(function (response) { + return response.data + }) + }, + delete: function (operationId, id) { + return $http.delete(ApiConfig.BASE_API + '/operations/' + operationId + '/aar/' + id).then(function (response) { + return response.data + }) + } + } +}) diff --git a/src/operations/templates/aar_controller.html b/src/operations/templates/aar_controller.html new file mode 100644 index 0000000..6c864ce --- /dev/null +++ b/src/operations/templates/aar_controller.html @@ -0,0 +1,19 @@ +
+
AAR
+
+ + + + +
+
+ {{ aar.name }} + {{ aar.length * 1000 | date: 'H:mm:ss': 'UTC' }} +
+ + +
+
+
diff --git a/src/operations/templates/aar_search.html b/src/operations/templates/aar_search.html new file mode 100644 index 0000000..96d75bd --- /dev/null +++ b/src/operations/templates/aar_search.html @@ -0,0 +1,43 @@ + + + diff --git a/src/operations/templates/edit_aar_controller.html b/src/operations/templates/edit_aar_controller.html new file mode 100644 index 0000000..e1fa40e --- /dev/null +++ b/src/operations/templates/edit_aar_controller.html @@ -0,0 +1,24 @@ +
AAR
+
+ + + + +
+
+ +
+ + {{ aar.name }} + {{ aar.length * 1000 | date: 'H:mm:ss': 'UTC' }} +
+ +
+ +
+