Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AAR integration #78

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/app/routes/operations/edit_operation.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<div class="row">
<div class="col-md-6">
<edit-operation-controller operation-id="operationId"></edit-operation-controller>
<edit-aar-controller operation-id="operationId"></edit-aar-controller>
<edit-addons-controller operation-id="operationId"></edit-addons-controller>
<edit-pws-controller operation-id="operationId"></edit-pws-controller>
<edit-steam-workshop-controller operation-id="operationId"></edit-steam-workshop-controller>
Expand Down
2 changes: 2 additions & 0 deletions src/app/routes/operations/operation.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
<div class="col-md-6">
<teamspeak-info></teamspeak-info>

<aar-controller operation-id="operationId"></aar-controller>

<addons-controller operation-id="operationId"></addons-controller>

<pws-controller operation-id="operationId"></pws-controller>
Expand Down
5 changes: 5 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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
Expand Down
23 changes: 23 additions & 0 deletions src/operations/controllers/aar_controller.js
Original file line number Diff line number Diff line change
@@ -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()
})
31 changes: 31 additions & 0 deletions src/operations/controllers/aar_search_controller.js
Original file line number Diff line number Diff line change
@@ -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()
})
59 changes: 59 additions & 0 deletions src/operations/controllers/edit_aar_controller.js
Original file line number Diff line number Diff line change
@@ -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()
})
9 changes: 9 additions & 0 deletions src/operations/directives/aar_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
angular.module('operations').directive('aarController', function () {
return {
controller: 'AARCtrl',
scope: {
operationId: '='
},
template: require('../templates/aar_controller.html')
}
})
9 changes: 9 additions & 0 deletions src/operations/directives/edit_aar_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
angular.module('operations').directive('editAarController', function () {
return {
controller: 'EditAARCtrl',
scope: {
operationId: '='
},
template: require('../templates/edit_aar_controller.html')
}
})
31 changes: 31 additions & 0 deletions src/operations/services/aar.js
Original file line number Diff line number Diff line change
@@ -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
})
}
}
})
19 changes: 19 additions & 0 deletions src/operations/templates/aar_controller.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<div ng-if="aars.length > 0">
<div class="block-title">AAR</div>
<div class="bordered-block">
<table width="100%" cellspacing="0">
<tr ng-repeat="aar in aars | orderBy: 'name' track by aar.id">
<td style="vertical-align: middle" ng-class-odd="'tbl1'" ng-class-even="'tbl2'">
<div ng-if="aar.name">
<a target="_blank" ng-href="{{aarUrl(aar)}}">{{ aar.name }}</a>
<small>{{ aar.length * 1000 | date: 'H:mm:ss': 'UTC' }}</small>
</div>

<div ng-if="!aar.name">
<a target="_blank" ng-href="{{aarUrl(aar)}}">{{ aar.aar_id }}</a>
</div>
</td>
</tr>
</table>
</div>
</div>
43 changes: 43 additions & 0 deletions src/operations/templates/aar_search.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<div class="modal-header">
<h3 class="modal-title">Lägg till AAR</h3>
</div>
<div class="modal-body">
<div class="progress" ng-if="loading" style="margin-top: 20px; margin-bottom: 10px;">
<div class="progress-bar progress-bar-striped active" role="progressbar" style="width: 100%">
</div>
</div>

<h4 ng-if="!loading && aars.length === 0">
Inga matchingar
</h4>

<div ng-if="aars.length > 0">
<h4>Matchningar: {{ aars.length }}</h4>
<table class="table">
<tbody>
<tr ng-repeat="aar in aars">
<td ng-class-odd="'tbl1'" ng-class-even="'tbl2'">
<p>
<a ng-href="{{aarUrl(aar)}}" target="_blank">
<strong>{{ aar.name }}</strong>
</a>
<small>{{ aar.length * 1000 | date: 'H:mm:ss': 'UTC' }}</small>
</p>
</td>
<td ng-class-odd="'tbl1'" ng-class-even="'tbl2'">
<p>
<a class="btn btn-primary pull-right" ng-click="add(aar)">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
Lägg till
</a>
<div class="clearfix"></div>
</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="modal-footer">
<button class="btn btn-primary" ng-click="close()">Stäng</button>
</div>
24 changes: 24 additions & 0 deletions src/operations/templates/edit_aar_controller.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<div class="block-title">AAR</div>
<div class="bordered-block ng-hide" ng-show="aars">
<table width="100%" cellspacing="0">
<tr ng-repeat="aar in aars | orderBy: 'name' track by aar.id">
<td style="vertical-align: middle" ng-class-odd="'tbl1'" ng-class-even="'tbl2'">
<form style="display: inline-block">
<button type="submit" class="btn btn-danger" ng-click="delete(aar)">
<span class="glyphicon glyphicon-trash" aria-hidden="true" title="Ta bort"></span>
</button>
</form>

<a ng-href="{{aarUrl(aar)}}" target="_blank">{{ aar.name }}</a>
<small>{{ aar.length * 1000 | date: 'H:mm:ss': 'UTC' }}</small>
</td>
</tr>
</table>

<div ng-show="operation" style="padding: 10px;">
<button class="btn btn-primary" ng-click="search()">
<span class="glyphicon glyphicon-search"></span>
Lägg till AAR
</button>
</div>
</div>