Skip to content

Commit

Permalink
Merge pull request #107 from SayakMukhopadhyay/wip
Browse files Browse the repository at this point in the history
Added tick detection
  • Loading branch information
SayakMukhopadhyay authored Jul 26, 2018
2 parents fb13aed + 1142516 commit 4c4127d
Show file tree
Hide file tree
Showing 19 changed files with 471 additions and 73 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "elitebgs",
"version": "2.1.1",
"version": "2.2.0",
"license": "Apache-2.0",
"scripts": {
"ng": "ng",
Expand Down
3 changes: 3 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ const ebgsFactionsV4 = require('./server/routes/elite_bgs_api/v4/factions');
const ebgsSystemsV4 = require('./server/routes/elite_bgs_api/v4/systems');
const ebgsStationsV4 = require('./server/routes/elite_bgs_api/v4/stations');

const tick = require('./server/routes/elite_bgs_api/v4/tick');

const authCheck = require('./server/routes/auth/auth_check');
const authDiscord = require('./server/routes/auth/discord');
const authLogout = require('./server/routes/auth/logout');
Expand Down Expand Up @@ -184,6 +186,7 @@ app.use('/api/eddb/v3/downloadupdate', downloadUpdateV3);
app.use('/api/ebgs/v4/factions', ebgsFactionsV4);
app.use('/api/ebgs/v4/systems', ebgsSystemsV4);
app.use('/api/ebgs/v4/stations', ebgsStationsV4);
app.use('/api/ebgs/v4/tick', tick);

app.use('/auth/check', authCheck);
app.use('/auth/discord', authDiscord);
Expand Down
3 changes: 2 additions & 1 deletion server/models/ebgs_history_system_v4.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ module.exports = new Promise((resolve, reject) => {
_id: false,
name: String,
name_lower: { type: String, lowercase: true }
}]
}],
tick_time: Date
}, { runSettersOnQuery: true });

let model = connection.model('ebgsHistorySystemV4', ebgsHistorySystem);
Expand Down
3 changes: 2 additions & 1 deletion server/models/ebgs_systems_v4.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ module.exports = new Promise((resolve, reject) => {
name: String,
name_lower: { type: String, lowercase: true }
}],
updated_at: Date
updated_at: Date,
tick_time: Date
}, { runSettersOnQuery: true });

ebgsSystem.plugin(mongoosePaginate);
Expand Down
37 changes: 37 additions & 0 deletions server/models/tick_times.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* KodeBlox Copyright 2017 Sayak Mukhopadhyay
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http: //www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

"use strict";

module.exports = new Promise((resolve, reject) => {
let db = require('../db');
let connection = db.elite_bgs;
let mongoose = db.mongoose;
let Schema = mongoose.Schema;

let tickTime = new Schema({
sol_start: Date,
sol_end: Date,
colonia_start: Date,
colonia_end: Date,
delta_minutes: Number,
start_gap_hours: Number
});

let model = connection.model('tickTimes', tickTime);

resolve(model);
})
201 changes: 148 additions & 53 deletions server/modules/eddn/schemas/journal.js

Large diffs are not rendered by default.

72 changes: 72 additions & 0 deletions server/routes/elite_bgs_api/v4/tick.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* KodeBlox Copyright 2017 Sayak Mukhopadhyay
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http: //www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

"use strict";

const express = require('express');
var cors = require('cors')
const _ = require('lodash');

let router = express.Router();

/**
* @swagger
* /tick:
* get:
* description: Get a ballpark range of the tick time in UTC. Note... This value is an estimate and not official.
* produces:
* - application/json
* parameters:
* - name: system
* description: Get the last recorded tick time for a system.
* in: query
* type: string
* responses:
* 200:
* description: An array of systems with historical data
* schema:
* type: array
* items:
* $ref: '#/definitions/Tick'
*/
router.get('/', cors(), (req, res, next) => {
if (req.query.system) {
require('../../../models/ebgs_systems_v4')
.then(systemModel => {
systemModel.findOne({
name_lower: req.query.system.toLowerCase()
}).then(result => {
res.status(200).json({
system_tick: result.tick_time
});
}).catch(next);
}).catch(next);
} else {
require('../../../models/tick_times')
.then(tickModel => {
tickModel.findOne({}).then(result => {
res.status(200).json({
sol_start: result.sol_start,
sol_end: result.sol_end,
colonia_start: result.colonia_start,
colonia_end: result.colonia_end
});
}).catch(next);
}).catch(next);
}
});

module.exports = router;
3 changes: 2 additions & 1 deletion server/swagger.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ let paramsEBGSAPIv4 = {
EBGSStationsV4: { properties: swaggerDefinitions.ebgsStationsV4 },
EBGSFactionsPageV4: { properties: swaggerDefinitions.pagination('EBGSFactionsV4') },
EBGSSystemsPageV4: { properties: swaggerDefinitions.pagination('EBGSSystemsV4') },
EBGSStationsPageV4: { properties: swaggerDefinitions.pagination('EBGSStationsV4') }
EBGSStationsPageV4: { properties: swaggerDefinitions.pagination('EBGSStationsV4') },
Tick: { properties: swaggerDefinitions.tick }
},
apis: ['./server/routes/elite_bgs_api/v4/*.js']
};
Expand Down
1 change: 1 addition & 0 deletions server/swaggerDefinitions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,4 @@ module.exports.solidComposition = require('./solid_composition');
module.exports.stationItems = require('./station_items');
module.exports.stations = require('./stations');
module.exports.systems = require('./systems');
module.exports.tick = require('./tick');
25 changes: 25 additions & 0 deletions server/swaggerDefinitions/tick.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* KodeBlox Copyright 2017 Sayak Mukhopadhyay
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http: //www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

"use strict";

module.exports = {
sol_start: { type: "string" },
sol_end: { type: "string" },
colonia_start: { type: "string" },
colonia_end: { type: "string" },
system_tick: { type: "string" }
}
53 changes: 49 additions & 4 deletions src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,56 @@
</a>
</div>
<div class="header-nav" [clr-nav-level]="1">
<a routerLink="/api/eddb" routerLinkActive="active" class="nav-link"><span class="nav-text">EDDB API</span></a>
<a routerLink="/api/ebgs" routerLinkActive="active" class="nav-link"><span class="nav-text">Elite BGS API</span></a>
<a routerLink="/bgsbot" routerLinkActive="active" class="nav-link"><span class="nav-text">BGSBot</span></a>
</div>
<a routerLink="/api/eddb" routerLinkActive="active" class="nav-link"><span class="nav-text">EDDB API</span></a>
<a routerLink="/api/ebgs" routerLinkActive="active" class="nav-link"><span class="nav-text">Elite BGS API</span></a>
<a routerLink="/bgsbot" routerLinkActive="active" class="nav-link"><span class="nav-text">BGSBot</span></a>
</div>
<div class="header-actions">
<span class="nav-link nav-text tick">Tick (UTC)</span>
<table class="tick">
<tr>
<td>Sol</td>
<td>
<div role="tooltip" aria-haspopup="true" class="tooltip tooltip-lg tooltip-bottom-right">
{{galacticTick.sol_start}}
<span class="tooltip-content">
Start of Tick in Sol Bubble
<br> Last Updated: {{galacticTickUpdate.sol_start}}
</span>
</div>
</td>
<td>
<div role="tooltip" aria-haspopup="true" class="tooltip tooltip-lg tooltip-bottom-right">
{{galacticTick.sol_end}}
<span class="tooltip-content">
End of Tick in Sol Bubble
<br> Last Updated: {{galacticTickUpdate.sol_end}}
</span>
</div>
</td>
</tr>
<tr>
<td>Colonia</td>
<td>
<div role="tooltip" aria-haspopup="true" class="tooltip tooltip-lg tooltip-bottom-right">
{{galacticTick.colonia_start}}
<span class="tooltip-content">
Start of Tick in Colonia Bubble
<br> Last Updated: {{galacticTickUpdate.colonia_start}}
</span>
</div>
</td>
<td>
<div role="tooltip" aria-haspopup="true" class="tooltip tooltip-lg tooltip-bottom-right">
{{galacticTick.colonia_end}}
<span class="tooltip-content">
End of Tick in Colonia Bubble
<br> Last Updated: {{galacticTickUpdate.colonia_end}}
</span>
</div>
</td>
</tr>
</table>
<a class="nav-icon nav-link" (click)="switchTheme()">
<clr-icon shape="sun" *ngIf="getThemeName() === 'dark'"></clr-icon>
<clr-icon shape="moon" *ngIf="getThemeName() === 'light'"></clr-icon>
Expand Down
27 changes: 26 additions & 1 deletion src/app/app.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,31 @@
top: 0;
}

.nav-icon img{
.nav-icon img {
border-radius: 50%;
}

.tick {
color: #fafafa;
opacity: 0.65;
}

.tick:hover {
opacity: 0.65 !important;
}

table.tick td {
padding: 0px 10px;
text-align: center;
}

table.tick td:first-child{
padding: 0px;
padding-right: 10px;
text-align: right;
font-weight: 600;
}

table.tick {
height: inherit;
}
18 changes: 17 additions & 1 deletion src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { Component, OnInit, Inject, PLATFORM_ID } from '@angular/core';
import { DOCUMENT, isPlatformBrowser } from '@angular/common';
import { AuthenticationService } from './services/authentication.service';
import { ThemeService } from './services/theme.service';
import { EBGSUser } from 'app/typings';
import { EBGSUser, GalacticTick } from 'app/typings';
import { TickService } from './services/tick.service';

@Component({
selector: 'app-root',
Expand All @@ -14,10 +15,13 @@ export class AppComponent implements OnInit {
isAuthenticated: boolean;
user: EBGSUser;
linkRef: HTMLLinkElement;
galacticTick: GalacticTick;
galacticTickUpdate: GalacticTick;

constructor(
private authenticationService: AuthenticationService,
private themeService: ThemeService,
private tickService: TickService,
@Inject(DOCUMENT) private document: Document,
@Inject(PLATFORM_ID) private platformId: Object
) {
Expand All @@ -28,10 +32,22 @@ export class AppComponent implements OnInit {
this.linkRef.onload = () => this.themeService.themeLoaded();
this.document.querySelector('head').appendChild(this.linkRef);
}
this.galacticTick = <GalacticTick>{};
this.galacticTickUpdate = <GalacticTick>{};
}

ngOnInit(): void {
this.getAuthentication();
this.getGalacticTick();
}

getGalacticTick() {
this.tickService
.getGalacticTick()
.subscribe(galacticTick => {
this.galacticTick = this.tickService.formatTickTime(galacticTick);
this.galacticTickUpdate = this.tickService.getUpdateTimeFromTick(galacticTick);
});
}

getAuthentication() {
Expand Down
3 changes: 2 additions & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { AuthenticationService } from './services/authentication.service';
import { ServerService } from './services/server.service';
import { TryAPIService } from './services/tryapi.service';
import { ThemeService } from './services/theme.service';
import { TickService } from './services/tick.service';

@NgModule({
declarations: [
Expand Down Expand Up @@ -60,7 +61,7 @@ import { ThemeService } from './services/theme.service';
AppRoutingModule,
ClarityModule
],
providers: [SystemsService, FactionsService, StationsService, AuthenticationService, ServerService, ThemeService, TryAPIService],
providers: [SystemsService, FactionsService, StationsService, AuthenticationService, ServerService, ThemeService, TryAPIService, TickService],
bootstrap: [AppComponent]
})
export class AppModule { }
7 changes: 7 additions & 0 deletions src/app/main/systems/system-view.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ <h1>You have been Banned from the website.</h1>
<p><b>State : </b>{{systemData?.state}}</p>
<p><b>Security : </b>{{systemData?.security}}</p>
<p><b>Population : </b>{{systemData?.population}}</p>
<p>
<b>Tick (UTC) : </b>{{systemTick?.system_tick}}
<span role="tooltip" aria-haspopup="true" class="tooltip tooltip-lg tooltip-bottom-right">
<clr-icon shape="info-circle" size="24"></clr-icon>
<span class="tooltip-content">Last Updated: {{systemTickUpdate?.system_tick}}</span>
</span>
</p>
<clr-datagrid>
<clr-dg-column [clrDgField]="'name'">Faction Name</clr-dg-column>
<clr-dg-column [clrDgField]="'influence'">Influence</clr-dg-column>
Expand Down
Loading

0 comments on commit 4c4127d

Please sign in to comment.