Replace some old syntax

This commit is contained in:
Valentin Kaelin 2019-04-05 22:41:32 +02:00
parent 2a12c38ab2
commit 0ad9788941
3 changed files with 30 additions and 43 deletions

View file

@ -3,12 +3,12 @@
* @param previous : time we want to get difference * @param previous : time we want to get difference
*/ */
export function timeDifference(previous) { export function timeDifference(previous) {
var current = new Date(); const current = new Date();
var msPerMinute = 60 * 1000; const msPerMinute = 60 * 1000;
var msPerHour = msPerMinute * 60; const msPerHour = msPerMinute * 60;
var msPerDay = msPerHour * 24; const msPerDay = msPerHour * 24;
var msPerWeek = msPerDay * 7; const msPerWeek = msPerDay * 7;
var elapsed = current - previous; const elapsed = current - previous;
if (elapsed < msPerMinute) { if (elapsed < msPerMinute) {
return Math.round(elapsed / 1000) + 's'; return Math.round(elapsed / 1000) + 's';
@ -19,9 +19,9 @@ export function timeDifference(previous) {
} else if (elapsed < msPerWeek) { } else if (elapsed < msPerWeek) {
return Math.round(elapsed / msPerDay) + 'j'; return Math.round(elapsed / msPerDay) + 'j';
} else { } else {
var oldDate = new Date(previous); const oldDate = new Date(previous);
var day = oldDate.getDate() < 10 ? '0' + oldDate.getDate() : oldDate.getDate(); const day = oldDate.getDate() < 10 ? '0' + oldDate.getDate() : oldDate.getDate();
var month = oldDate.getMonth() < 9 ? '0' + (oldDate.getMonth() + 1) : (oldDate.getMonth() + 1); const month = oldDate.getMonth() < 9 ? '0' + (oldDate.getMonth() + 1) : (oldDate.getMonth() + 1);
return day + '.' + month + '.' + oldDate.getFullYear().toString().substr(-2); return day + '.' + month + '.' + oldDate.getFullYear().toString().substr(-2);
} }
} }
@ -32,8 +32,8 @@ export function timeDifference(previous) {
* @param sec : time in seconds to convert * @param sec : time in seconds to convert
*/ */
export function secToTime(sec) { export function secToTime(sec) {
var min = Math.floor(sec / 60); const min = Math.floor(sec / 60);
var newSec = sec - min * 60; const newSec = sec - min * 60;
return min + ':' + (newSec < 10 ? '0' + newSec : newSec); // return min + ':' + (newSec < 10 ? '0' + newSec : newSec); //
} }

View file

@ -82,8 +82,8 @@ export default {
this.loading = true; this.loading = true;
this.axios({ this.axios({
method: "POST", method: "POST",
url: "https://vue.valentinkaelin.ch/api", // url: "https://vue.valentinkaelin.ch/api",
//url: "http://localhost:5000/api", url: "http://localhost:5000/api",
headers: { headers: {
"Content-Type": "application/json" "Content-Type": "application/json"
}, },
@ -131,20 +131,10 @@ export default {
// Loop on all matches // Loop on all matches
for (let i = 0; i < matches.length; i++) { for (let i = 0; i < matches.length; i++) {
const currentMatch = matches[i]; const currentMatch = matches[i];
let participantId; const participantId = currentMatch.participantIdentities.find((p) => p.player.accountId === userStats.accountId).participantId
for (let i = 0; i < currentMatch.participantIdentities.length; i++) {
if (currentMatch.participantIdentities[i].player.accountId === userStats.accountId)
participantId = currentMatch.participantIdentities[i].participantId;
}
const teamId = currentMatch.participants[participantId - 1].teamId; const teamId = currentMatch.participants[participantId - 1].teamId;
let win = false; const win = currentMatch.teams.find((t) => t.teamId === teamId).win === 'Win'
for (let i = 0; i < currentMatch.teams.length; i++) {
if (currentMatch.teams[i].teamId === teamId) {
if (currentMatch.teams[i].win === 'Win')
win = true;
}
}
const map = maps[currentMatch.mapId]; const map = maps[currentMatch.mapId];
let mode = gameModes[currentMatch.queueId]; let mode = gameModes[currentMatch.queueId];
@ -189,7 +179,7 @@ export default {
firstSum: this.getSummonerLink(firstSum), firstSum: this.getSummonerLink(firstSum),
secondSum: this.getSummonerLink(secondSum) secondSum: this.getSummonerLink(secondSum)
}); });
} } // end loop matches
console.log(matchesInfos); console.log(matchesInfos);
this.localInfos = { this.localInfos = {
@ -219,11 +209,8 @@ export default {
return `url('https://cdn.valentinkaelin.ch/riot/${itemImage.sprite}') -${itemImage.x}px -${itemImage.y}px`; return `url('https://cdn.valentinkaelin.ch/riot/${itemImage.sprite}') -${itemImage.x}px -${itemImage.y}px`;
}, },
getSummonerLink(id) { getSummonerLink(id) {
for(var prop in summonersJSON.data) { const spellName = Object.entries(summonersJSON.data).find(([, spell]) => Number(spell.key) === id)[0]
if(summonersJSON.data[prop].key == id) { return `https://cdn.valentinkaelin.ch/riot/spells/${spellName}.png`;
return `https://cdn.valentinkaelin.ch/riot/spells/${summonersJSON.data[prop].id}.png`;
}
}
}, },
redirect() { redirect() {
this.$router.push("/summoner/" + this.search) this.$router.push("/summoner/" + this.search)

View file

@ -20,21 +20,21 @@ let finalJSON = [];
app.set('port', (process.env.PORT || 5000)) app.set('port', (process.env.PORT || 5000))
/* DEV */ /* DEV */
//var cors = require('cors'); var cors = require('cors');
//app.use(cors({origin: '*'})); app.use(cors({origin: '*'}));
/* PRODUCTION */ /* PRODUCTION */
const staticFileMiddleware = express.static(path.join(__dirname + '/dist')); // const staticFileMiddleware = express.static(path.join(__dirname + '/dist'));
app.use(staticFileMiddleware); // app.use(staticFileMiddleware);
app.use(history({ // app.use(history({
disableDotRule: true, // disableDotRule: true,
verbose: true // verbose: true
})); // }));
app.use(staticFileMiddleware); // app.use(staticFileMiddleware);
app.get('/', function (req, res) { // app.get('/', function (req, res) {
res.render(path.join(__dirname + '/dist/index.html')); // res.render(path.join(__dirname + '/dist/index.html'));
}); // });
/* To retrieve data of post request */ /* To retrieve data of post request */
app.use(bodyParser.json()); // to support JSON-encoded bodies app.use(bodyParser.json()); // to support JSON-encoded bodies