This repository has been archived by the owner on Apr 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
502 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const { Model } = require('sequelize') | ||
module.exports = (sequelize, DataTypes) => { | ||
class Map extends Model {} | ||
|
||
Map.init( | ||
{ | ||
id: { | ||
allowNull: false, | ||
primaryKey: true, | ||
type: DataTypes.UUID, | ||
}, | ||
name: { | ||
allowNull: false, | ||
type: DataTypes.STRING, | ||
}, | ||
lines_to_show: { | ||
allowNull: false, | ||
type: DataTypes.STRING, | ||
defaultValue: '', | ||
}, | ||
network_id: { | ||
allowNull: false, | ||
type: DataTypes.UUID, | ||
}, | ||
}, | ||
|
||
{ | ||
sequelize, | ||
tableName: 'Map', | ||
modelName: 'Map', | ||
}, | ||
) | ||
|
||
// Map.associate = (models) => { | ||
// Map.belongsTo(models.Network, { | ||
// onDelete: 'cascade', | ||
// foreignKey: 'map_id', | ||
// }) | ||
// } | ||
|
||
return Map | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
const express = require('express') | ||
const router = express.Router() | ||
|
||
const uuid = require('uuid') | ||
|
||
const { Network, Line, Station, Connection, Map } = require('../models') | ||
const { NotificationCookie, FormRestoreCookie } = require('../helpers/cookie_options') | ||
const { Op } = require('sequelize') | ||
|
||
router.get('/', async (req, res) => { | ||
const networks = await Network.findAll({ | ||
attributes: ['id', 'name'], | ||
raw: true, | ||
}) | ||
|
||
const maps = await Map.findAll({ | ||
attributes: ['id', 'name'], | ||
raw: true, | ||
}) | ||
|
||
const data = { | ||
data: { | ||
networks, | ||
maps, | ||
}, | ||
} | ||
return res.render('maps/index', data) | ||
}) | ||
|
||
router.post('/', async (req, res) => { | ||
const { name, networkToMap } = req.body | ||
|
||
await Map.create({ | ||
id: uuid.v4(), | ||
name: name, | ||
network_id: networkToMap, | ||
}) | ||
|
||
res.cookie('notification', `${name} has been created.`, NotificationCookie) | ||
return res.redirect('back') | ||
}) | ||
|
||
router.get('/edit/:mapID', async (req, res) => { | ||
const { mapID } = req.params | ||
|
||
const currentMap = await Map.findOne({ | ||
where: { id: mapID }, | ||
raw: true, | ||
}) | ||
|
||
const mapNetwork = await Network.findOne({ | ||
where: { | ||
id: currentMap.network_id, | ||
}, | ||
include: [ | ||
{ | ||
model: Line, | ||
}, | ||
], | ||
}) | ||
|
||
// Data for rendering the map | ||
const Lines = await Line.findAll({ | ||
where: { | ||
id: { | ||
[Op.in]: currentMap.lines_to_show.split(',') || [currentMap.lines_to_show], | ||
}, | ||
network_id: currentMap.network_id, | ||
}, | ||
include: [ | ||
{ | ||
model: Station, | ||
include: [ | ||
{ | ||
model: Connection, | ||
}, | ||
], | ||
}, | ||
], | ||
}) | ||
|
||
const data = { | ||
data: { | ||
currentMap: currentMap, | ||
mapNetwork: mapNetwork, | ||
selectedLines: Lines, | ||
}, | ||
layout: 'map_editor', | ||
} | ||
return res.render('maps/editor', data) | ||
}) | ||
|
||
router.post('/edit/:mapID', async (req, res) => { | ||
const { mapID } = req.params | ||
const { linesToDisplay } = req.body | ||
|
||
let linesToDisplayArray | ||
|
||
// Check whether linesToDisplay is valid | ||
if (!linesToDisplay) { | ||
linesToDisplayArray = [] | ||
} else { | ||
// Check whether linesToDisplay is array | ||
if (!Array.isArray(linesToDisplay)) { | ||
// Convert linesToDisplay to array | ||
linesToDisplayArray = linesToDisplay.split(',') | ||
} else { | ||
linesToDisplayArray = linesToDisplay | ||
} | ||
} | ||
|
||
await Map.update({ | ||
lines_to_show: linesToDisplayArray.toString(), | ||
}, { | ||
where: { | ||
id: mapID, | ||
}, | ||
}) | ||
|
||
return res.redirect('back') | ||
}) | ||
|
||
module.exports = router |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
.node { | ||
height: 1.5rem; | ||
width: 1.5rem; | ||
border-radius: 50%; | ||
background-color: #fff; | ||
border: 4px #000 solid; | ||
margin-top: -1.25rem; | ||
} | ||
|
||
.line { | ||
height: 1rem; | ||
width: 5.25rem; | ||
margin-right: -.8rem; | ||
/* z-index: 1 */ | ||
border-radius: 6rem; | ||
} | ||
|
||
.line-section { | ||
display: inline-block; | ||
min-height: min-content; | ||
height: 12rem; | ||
} | ||
|
||
.station-name { | ||
font-weight: 600; | ||
/* rotate: y 45deg; */ | ||
transform: rotate(45deg) translate(1rem, -1rem); | ||
transform-origin: 0 0; | ||
width: 0; | ||
height: auto; | ||
white-space: nowrap; | ||
line-height: 1rem; | ||
} |
Oops, something went wrong.