Skip to content

Commit 687da22

Browse files
committed
AAR integration
1 parent 6927826 commit 687da22

12 files changed

+256
-0
lines changed

src/app/routes/operations/edit_operation.html

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<div class="row">
33
<div class="col-md-6">
44
<edit-operation-controller operation-id="operationId"></edit-operation-controller>
5+
<edit-aar-controller operation-id="operationId"></edit-aar-controller>
56
<edit-addons-controller operation-id="operationId"></edit-addons-controller>
67
<edit-pws-controller operation-id="operationId"></edit-pws-controller>
78
<edit-steam-workshop-controller operation-id="operationId"></edit-steam-workshop-controller>

src/app/routes/operations/operation.html

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
<div class="col-md-6">
1010
<teamspeak-info></teamspeak-info>
1111

12+
<aar-controller operation-id="operationId"></aar-controller>
13+
1214
<addons-controller operation-id="operationId"></addons-controller>
1315

1416
<pws-controller operation-id="operationId"></pws-controller>

src/index.js

+5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ var app = angular.module('app', [
1515

1616
app.constant('ApiConfig', {
1717
BASE_API: 'https://api.anrop.se',
18+
BASE_AAR_API: 'https://api.aar.anrop.se',
1819
BASE_ARMA3SYNC_API: 'https://arma3sync.anrop.se/manager/api',
1920
BASE_PWS_API: 'https://playwithsix.anrop.se',
2021
BASE_STEAM_WORKSHOP_API: 'https://steam-workshop.anrop.se',
@@ -25,6 +26,10 @@ app.constant('ImgurConfig', {
2526
API_KEY: 'Client-ID c068f0d04c394eb'
2627
})
2728

29+
app.constant('WebConfig', {
30+
BASE_AAR_WEB: 'https://aar.anrop.se'
31+
})
32+
2833
app.config(function ($locationProvider, $routeProvider) {
2934
$locationProvider.html5Mode(true)
3035
$routeProvider
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
angular.module('operations').controller('AARCtrl', function ($scope, WebConfig, AARSvc) {
2+
$scope.aarUrl = function (aar) {
3+
return WebConfig.BASE_AAR_WEB + '/missions/' + aar.aar_id
4+
}
5+
6+
$scope.load = function () {
7+
AARSvc.operation($scope.operationId).then(function (aars) {
8+
aars.forEach(function (aar) {
9+
AARSvc.mission(aar.aar_id).then(function (info) {
10+
Object.assign(aar, {
11+
length: info.length,
12+
name: info.name,
13+
world: info.world
14+
})
15+
})
16+
})
17+
18+
$scope.aars = aars
19+
})
20+
}
21+
22+
$scope.load()
23+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
angular.module('operations').controller('AARSearchCtrl', function ($scope, $uibModalInstance, WebConfig, AARSvc) {
2+
$scope.aars = []
3+
$scope.loading = false
4+
5+
$scope.aarUrl = function (aar) {
6+
return WebConfig.BASE_AAR_WEB + '/missions/' + aar.id
7+
}
8+
9+
$scope.load = function (query) {
10+
$scope.aars = []
11+
$scope.loading = true
12+
AARSvc.missions().then(function (aars) {
13+
var operationDate = new Date($scope.operation.start)
14+
$scope.aars = aars.filter(function (aar) {
15+
var aarDate = new Date(aar.created_at)
16+
return (
17+
aarDate.getFullYear() === operationDate.getFullYear() &&
18+
aarDate.getMonth() === operationDate.getMonth() &&
19+
aarDate.getDate() === operationDate.getDate()
20+
)
21+
})
22+
$scope.loading = false
23+
})
24+
}
25+
26+
$scope.close = function () {
27+
$uibModalInstance.dismiss('cancel')
28+
}
29+
30+
$scope.load()
31+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
angular.module('operations').controller('EditAARCtrl', function ($scope, $uibModal, WebConfig, AARSvc, OperationSvc) {
2+
$scope.add = function (data) {
3+
var found = $scope.aars.filter(function (aar) {
4+
return aar.aar_id === data.id
5+
})
6+
7+
if (found.length === 0) {
8+
return AARSvc.add($scope.operationId, { aar_id: data.id }).then(function () {
9+
loadAARs()
10+
return this
11+
})
12+
}
13+
}
14+
15+
$scope.aarUrl = function (aar) {
16+
return WebConfig.BASE_AAR_WEB + '/missions/' + aar.aar_id
17+
}
18+
19+
$scope.delete = function (aar) {
20+
AARSvc.delete($scope.operationId, aar.id).then(function () {
21+
loadAARs()
22+
return this
23+
})
24+
}
25+
26+
$scope.search = function () {
27+
$uibModal.open({
28+
template: require('../templates/aar_search.html'),
29+
controller: 'AARSearchCtrl',
30+
scope: $scope
31+
}).result.then(function () {
32+
33+
}, function () {
34+
35+
})
36+
}
37+
38+
var loadAARs = function () {
39+
OperationSvc.operation($scope.operationId).then(function (operation) {
40+
$scope.operation = operation
41+
})
42+
43+
AARSvc.operation($scope.operationId).then(function (aars) {
44+
aars.forEach(function (aar) {
45+
AARSvc.mission(aar.aar_id).then(function (info) {
46+
Object.assign(aar, {
47+
length: info.length,
48+
name: info.name,
49+
world: info.world
50+
})
51+
})
52+
})
53+
54+
$scope.aars = aars
55+
})
56+
}
57+
58+
loadAARs()
59+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
angular.module('operations').directive('aarController', function () {
2+
return {
3+
controller: 'AARCtrl',
4+
scope: {
5+
operationId: '='
6+
},
7+
template: require('../templates/aar_controller.html')
8+
}
9+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
angular.module('operations').directive('editAarController', function () {
2+
return {
3+
controller: 'EditAARCtrl',
4+
scope: {
5+
operationId: '='
6+
},
7+
template: require('../templates/edit_aar_controller.html')
8+
}
9+
})

src/operations/services/aar.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
angular.module('operations').factory('AARSvc', function ($http, ApiConfig) {
2+
return {
3+
missions: function () {
4+
return $http.get(ApiConfig.BASE_AAR_API + '/missions').then(function (response) {
5+
return response.data
6+
})
7+
},
8+
mission: function (id) {
9+
return $http.get(ApiConfig.BASE_AAR_API + '/missions/' + id).then(function (response) {
10+
return response.data
11+
})
12+
},
13+
operation: function (operationId) {
14+
return $http.get(ApiConfig.BASE_API + '/operations/' + operationId + '/aar').then(function (response) {
15+
return response.data
16+
})
17+
},
18+
add: function (operationId, data) {
19+
return $http.post(ApiConfig.BASE_API + '/operations/' + operationId + '/aar', {
20+
aar: data
21+
}).then(function (response) {
22+
return response.data
23+
})
24+
},
25+
delete: function (operationId, id) {
26+
return $http.delete(ApiConfig.BASE_API + '/operations/' + operationId + '/aar/' + id).then(function (response) {
27+
return response.data
28+
})
29+
}
30+
}
31+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<div ng-if="aars.length > 0">
2+
<div class="block-title">AAR</div>
3+
<div class="bordered-block">
4+
<table width="100%" cellspacing="0">
5+
<tr ng-repeat="aar in aars | orderBy: 'name' track by aar.id">
6+
<td style="vertical-align: middle" ng-class-odd="'tbl1'" ng-class-even="'tbl2'">
7+
<div ng-if="aar.name">
8+
<a target="_blank" ng-href="{{aarUrl(aar)}}">{{ aar.name }}</a>
9+
<small>{{ aar.length * 1000 | date: 'H:mm:ss': 'UTC' }}</small>
10+
</div>
11+
12+
<div ng-if="!aar.name">
13+
<a target="_blank" ng-href="{{aarUrl(aar)}}">{{ aar.aar_id }}</a>
14+
</div>
15+
</td>
16+
</tr>
17+
</table>
18+
</div>
19+
</div>
+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<div class="modal-header">
2+
<h3 class="modal-title">Lägg till AAR</h3>
3+
</div>
4+
<div class="modal-body">
5+
<div class="progress" ng-if="loading" style="margin-top: 20px; margin-bottom: 10px;">
6+
<div class="progress-bar progress-bar-striped active" role="progressbar" style="width: 100%">
7+
</div>
8+
</div>
9+
10+
<h4 ng-if="!loading && aars.length === 0">
11+
Inga matchingar
12+
</h4>
13+
14+
<div ng-if="aars.length > 0">
15+
<h4>Matchningar: {{ aars.length }}</h4>
16+
<table class="table">
17+
<tbody>
18+
<tr ng-repeat="aar in aars">
19+
<td ng-class-odd="'tbl1'" ng-class-even="'tbl2'">
20+
<p>
21+
<a ng-href="{{aarUrl(aar)}}" target="_blank">
22+
<strong>{{ aar.name }}</strong>
23+
</a>
24+
<small>{{ aar.length * 1000 | date: 'H:mm:ss': 'UTC' }}</small>
25+
</p>
26+
</td>
27+
<td ng-class-odd="'tbl1'" ng-class-even="'tbl2'">
28+
<p>
29+
<a class="btn btn-primary pull-right" ng-click="add(aar)">
30+
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
31+
Lägg till
32+
</a>
33+
<div class="clearfix"></div>
34+
</p>
35+
</td>
36+
</tr>
37+
</tbody>
38+
</table>
39+
</div>
40+
</div>
41+
<div class="modal-footer">
42+
<button class="btn btn-primary" ng-click="close()">Stäng</button>
43+
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<div class="block-title">AAR</div>
2+
<div class="bordered-block ng-hide" ng-show="aars">
3+
<table width="100%" cellspacing="0">
4+
<tr ng-repeat="aar in aars | orderBy: 'name' track by aar.id">
5+
<td style="vertical-align: middle" ng-class-odd="'tbl1'" ng-class-even="'tbl2'">
6+
<form style="display: inline-block">
7+
<button type="submit" class="btn btn-danger" ng-click="delete(aar)">
8+
<span class="glyphicon glyphicon-trash" aria-hidden="true" title="Ta bort"></span>
9+
</button>
10+
</form>
11+
12+
<a ng-href="{{aarUrl(aar)}}" target="_blank">{{ aar.name }}</a>
13+
<small>{{ aar.length * 1000 | date: 'H:mm:ss': 'UTC' }}</small>
14+
</td>
15+
</tr>
16+
</table>
17+
18+
<div ng-show="operation" style="padding: 10px;">
19+
<button class="btn btn-primary" ng-click="search()">
20+
<span class="glyphicon glyphicon-search"></span>
21+
Lägg till AAR
22+
</button>
23+
</div>
24+
</div>

0 commit comments

Comments
 (0)