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

feat: initial route support #781

Merged
merged 58 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
967a653
feat: initial route support
TurtIeSocks Jul 27, 2023
be46e32
fix: types
TurtIeSocks Jul 27, 2023
2cf18c2
fix: missing $
TurtIeSocks Jul 27, 2023
aed2774
fix: dumb ui
TurtIeSocks Jul 27, 2023
4f7312f
fix: query correctly & popup management
TurtIeSocks Jul 27, 2023
30e92ac
fix: filter by start and end
TurtIeSocks Jul 28, 2023
7805a58
styling: show game icons
TurtIeSocks Jul 28, 2023
4609297
fix: dump of info in popup
TurtIeSocks Jul 28, 2023
1db5ada
0m fallback
TurtIeSocks Jul 28, 2023
0bd5809
fix: areaRestrictions
TurtIeSocks Jul 28, 2023
6e58e86
fix: `routes` translation
TurtIeSocks Jul 28, 2023
ab8cb0c
fix: add routes to allowed menu items
TurtIeSocks Jul 28, 2023
59e779b
fix: tag and waypoint fallbacks
TurtIeSocks Jul 28, 2023
6bf28b1
styling: remove circles on waypoints
TurtIeSocks Jul 28, 2023
3b9922f
fix: change poi translation
TurtIeSocks Jul 28, 2023
51cb714
styling: popup cleanup
TurtIeSocks Jul 28, 2023
f929298
styling: trim description
TurtIeSocks Jul 28, 2023
d776ac6
Update Route.jsx
TurtIeSocks Jul 28, 2023
1406656
feat: add start/end image support and navigation icon
TurtIeSocks Jul 28, 2023
e641157
minor version bump
TurtIeSocks Jul 28, 2023
ef1a8b0
styling: use image_border_color for route
TurtIeSocks Jul 28, 2023
a0c09a9
styling: center align tags too
TurtIeSocks Jul 28, 2023
178f1d2
fix: missing perm image/translation
TurtIeSocks Jul 28, 2023
36ed5fd
Merge branch 'develop' into route-support
TurtIeSocks Jul 28, 2023
b016ec3
Update locales/en.json
TurtIeSocks Jul 28, 2023
7cad59e
fix: add helpers for route/routes
TurtIeSocks Jul 28, 2023
4072d8e
fix: update timer when expireTime changes
TurtIeSocks Jul 28, 2023
b64a562
styling: restyle popup a bit
TurtIeSocks Jul 28, 2023
d03931c
fix: move popup anchor up a smidge
TurtIeSocks Jul 28, 2023
08ec96c
styling: minor popup tip styling
TurtIeSocks Jul 28, 2023
20d815f
styling: add duration and hide some info
TurtIeSocks Jul 28, 2023
1ed1749
feat: add some event listeners to the route line
TurtIeSocks Jul 28, 2023
f0f7628
fix: menu order when started with `yarn start`
TurtIeSocks Jul 28, 2023
7dd2d54
fix: better click behavior
TurtIeSocks Jul 28, 2023
e1735b0
fix: optimize click/hover behavior
TurtIeSocks Jul 28, 2023
02bc11a
fix: various
TurtIeSocks Jul 28, 2023
7e14bc2
styling: set opacity for extra contrast
TurtIeSocks Jul 29, 2023
4b6b9fb
styling: marker opacity and offsets
TurtIeSocks Jul 29, 2023
1a36d3f
fix: remove log
TurtIeSocks Jul 29, 2023
5aed6e4
fix: area restrictions
TurtIeSocks Jul 29, 2023
283919b
feat: initial route distance filtering
TurtIeSocks Jul 29, 2023
339ad89
Merge branch 'develop' into route-support
TurtIeSocks Jul 29, 2023
31f1d2a
feat: finish distance slider filter
TurtIeSocks Jul 29, 2023
8f7d73a
version bump
TurtIeSocks Jul 29, 2023
5f4d118
fix: min val
TurtIeSocks Jul 29, 2023
5d8d709
fix: lock vite deps
TurtIeSocks Jul 31, 2023
dfee19c
feat: elevation stats
TurtIeSocks Jul 31, 2023
e42ff33
fix: logic
TurtIeSocks Jul 31, 2023
43e797d
Sync CI/CD Config Items
turtlesocks-bot Jul 29, 2023
5d5142a
Update de.json
acocalypso Jul 30, 2023
29e221b
feat: add discord prompt
lenisko Jul 31, 2023
35bebd4
fix: missing place
lenisko Jul 31, 2023
0932f35
fix
lenisko Jul 31, 2023
a562d80
fix: lint
lenisko Jul 31, 2023
295e17d
Update types.d.ts
TurtIeSocks Aug 1, 2023
48d0ac6
Merge branch 'develop' into route-support
TurtIeSocks Aug 1, 2023
330ed9a
Merge pull request #789 from lenisko/prompt
TurtIeSocks Aug 1, 2023
4d9add5
fix: color consistency
TurtIeSocks Aug 1, 2023
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
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"i18n-ally.localesPaths": [
"public/base-locales"
"locales"
],
"i18n-ally.keystyle": "flat",
"[javascript]": {
Expand Down
12 changes: 11 additions & 1 deletion locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -626,5 +626,15 @@
"level_circles": "Level Indicators",
"min_level_circle": "Minimum Circle Level",
"mutation_auth_error": "Your request was unsuccessful due to not being logged in",
"submitted_by": "Submitted By"
"submitted_by": "Submitted By",
"reversible": "Reversible",
"version": "Version",
"route_tags": "Route Tags",
"routes": "Routes",
"route_type": "Route Type",
"routes_subtitle": "View in game routes and relevant information about them on the map",
"description": "Description",
"additional_info": "Additional Info",
"duration": "Duration",
"elevation": "Elevation"
}
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "reactmap",
"version": "1.21.1",
"version": "1.22.2",
"description": "React based frontend map.",
"main": "ReactMap.js",
"author": "TurtIeSocks <[email protected]>",
Expand Down Expand Up @@ -35,10 +35,10 @@
"yarn": "^1.22.x"
},
"devDependencies": {
"@sentry/vite-plugin": "^2.2.1",
"@sentry/vite-plugin": "2.2.1",
"@types/react": "^18.2.15",
"@types/react-dom": "^18.2.7",
"@vitejs/plugin-react": "^4.0.0",
"@vitejs/plugin-react": "4.0.0",
"eslint": "^8.44.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-prettier": "^8.8.0",
Expand All @@ -50,9 +50,9 @@
"nodemon": "^2.0.22",
"prettier": "^2.8.8",
"rollup-plugin-delete": "^2.0.0",
"vite": "^4.3.9",
"vite-plugin-checker": "^0.6.0",
"vite-plugin-static-copy": "^0.16.0"
"vite": "4.3.9",
"vite-plugin-checker": "0.6.0",
"vite-plugin-static-copy": "0.16.0"
},
"dependencies": {
"@apollo/client": "^3.7.15",
Expand Down
Binary file added public/images/perms/routes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions server/scripts/configMigration.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ const mergeAuth = async () => {
allowedGuilds: obj?.allowedGuilds,
blockedGuilds: obj?.blockedGuilds,
allowedUsers: obj?.allowedUsers,
clientPrompt: obj?.clientPrompt,
})

const telegramObj = (obj, name) => ({
Expand Down
11 changes: 11 additions & 0 deletions server/src/configs/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"pokemon": 20,
"pokestops": 300,
"portals": 300,
"routes": 10000,
"scanAreas": 10000,
"scanCells": 10,
"submissionCells": 500,
Expand Down Expand Up @@ -133,6 +134,7 @@
"nests",
"pokestops",
"pokemon",
"routes",
"wayfarer",
"s2cells",
"scanAreas",
Expand Down Expand Up @@ -564,6 +566,9 @@
"portals": {
"enabled": false
},
"routes": {
"enabled": true
},
"scanAreas": {
"enabled": false
},
Expand Down Expand Up @@ -661,6 +666,7 @@
"allowedGuilds": [],
"blockedGuilds": [],
"allowedUsers": [],
"clientPrompt": "consent",
"thumbnailUrl": "https://user-images.githubusercontent.com/58572875/167069223-745a139d-f485-45e3-a25c-93ec4d09779c.png",
"trialPeriod": {
"start": {
Expand Down Expand Up @@ -835,6 +841,11 @@
"enabled": true,
"trialPeriodEligible": false,
"roles": []
},
"routes": {
"enabled": true,
"trialPeriodEligible": false,
"roles": []
}
}
},
Expand Down
8 changes: 7 additions & 1 deletion server/src/configs/local.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"pokestop",
"scanCell",
"spawnpoint",
"weather"
"weather",
"route"
]
},
{
Expand Down Expand Up @@ -236,6 +237,11 @@
"enabled": true,
"trialPeriodEligible": false,
"roles": []
},
"routes": {
"enabled": true,
"trialPeriodEligible": false,
"roles": []
}
}
},
Expand Down
15 changes: 14 additions & 1 deletion server/src/graphql/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const { S2LatLng, S2RegionCoverer, S2LatLngRect } = require('nodes2ts')
const config = require('../services/config')
const Utility = require('../services/Utility')
const Fetch = require('../services/Fetch')
const buildDefaultFilters = require('../services/filters/builder/base')

/**
* @typedef {(parent: unknown, args: object, context: import('../types').GqlContext) => unknown} Resolver
Expand All @@ -28,7 +29,7 @@ const resolvers = {
return {
...available,
masterfile: { ...Event.masterfile, invasions: Event.invasions },
filters: Utility.buildDefaultFilters(perms, available, Db.models),
filters: buildDefaultFilters(perms, available, Db),
}
},
backup: (_, args, { req, perms, Db }) => {
Expand Down Expand Up @@ -141,6 +142,18 @@ const resolvers = {
}
return {}
},
route: (_, args, { perms, Db }) => {
if (perms?.routes) {
return Db.query('Route', 'getOne', args.id)
}
return {}
},
routes: (_, args, { perms, Db }) => {
if (perms?.routes) {
return Db.query('Route', 'getAll', perms, args)
}
return []
},
s2cells: (_, args, { perms }) => {
if (perms?.s2cells) {
const { onlyCells } = args.filters
Expand Down
30 changes: 30 additions & 0 deletions server/src/graphql/scannerTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,34 @@ module.exports = gql`
status: String
message: String
}

type Waypoint {
lat_degrees: Float
lng_degrees: Float
elevation_in_meters: Float
}

type Route {
id: ID
name: String
description: String
distance_meters: Int
duration_seconds: Int
start_fort_id: String
start_lat: Float
start_lon: Float
start_image: String
end_fort_id: String
end_lat: Float
end_lon: Float
end_image: String
image: String
image_border_color: String
reversible: Boolean
tags: [String]
type: Int
updated: Int
version: Int
waypoints: [Waypoint]
}
`
8 changes: 8 additions & 0 deletions server/src/graphql/typeDefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@ module.exports = gql`
maxLon: Float
filters: JSON
): [Weather]
route(id: ID): Route
routes(
minLat: Float
maxLat: Float
minLon: Float
maxLon: Float
filters: JSON
): [Route]
webhook(category: String, status: String, name: String): Poracle
scanner(category: String, method: String, data: JSON): ScannerApi
}
Expand Down
1 change: 1 addition & 0 deletions server/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ connection.migrate.latest().then(async () => {
await Db.getDbContext()
await Promise.all([
Db.historicalRarity(),
Db.getFilterContext(),
Event.setAvailable('gyms', 'Gym', Db),
Event.setAvailable('pokestops', 'Pokestop', Db),
Event.setAvailable('pokemon', 'Pokemon', Db),
Expand Down
105 changes: 105 additions & 0 deletions server/src/models/Route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
const { Model } = require('objection')
const getAreaSql = require('../services/functions/getAreaSql')

const GET_ALL_SELECT = /** @type {const} */ ([
'id',
'start_lat',
'start_lon',
'end_lat',
'end_lon',
'waypoints',
'image_border_color',
'reversible',
])

class Route extends Model {
static get tableName() {
return 'route'
}

/**
* Returns the bare essentials for displaying on the map
* @param {import('../types').Permissions} perms
* @param {object} args
* @param {import('../types').DbContext} ctx
* @returns
*/
static async getAll(perms, args, ctx) {
const { areaRestrictions } = perms
const { onlyAreas, onlyDistance } = args.filters

const distanceInMeters = (onlyDistance || [0.5, 100]).map((x) => x * 1000)

const query = this.query()
.select(GET_ALL_SELECT)
.whereBetween('start_lat', [args.minLat, args.maxLat])
.andWhereBetween('start_lon', [args.minLon, args.maxLon])
.andWhereBetween('distance_meters', distanceInMeters)
.union((qb) => {
qb.select(GET_ALL_SELECT)
.whereBetween('end_lat', [args.minLat, args.maxLat])
.andWhereBetween('end_lon', [args.minLon, args.maxLon])
.andWhereBetween('distance_meters', distanceInMeters)
.from('route')

getAreaSql(qb, areaRestrictions, onlyAreas, ctx.isMad, 'route')
})

if (!getAreaSql(query, areaRestrictions, onlyAreas, ctx.isMad, 'route')) {
return []
}
const results = await query

return results.map((result) => {
if (typeof result.waypoints === 'string') {
result.waypoints = JSON.parse(result.waypoints)
} else if (result.waypoints === null) {
result.waypoints = []
}
return result
})
}

/**
* Returns the full route after querying it, generally from the Popup
* @param {number} id
*/
static async getOne(id) {
const result = await this.query().findById(id)
if (typeof result.waypoints === 'string') {
result.waypoints = JSON.parse(result.waypoints)
} else if (result.waypoints === null) {
result.waypoints = []
}
if (typeof result.tags === 'string') {
result.tags = JSON.parse(result.tags)
} else if (result.tags === null) {
result.tags = []
}
if (typeof result.image === 'string') {
result.image = result.image.replace('http://', 'https://')
}
if (typeof result.start_image === 'string') {
result.start_image = result.start_image.replace('http://', 'https://')
}
if (typeof result.end_image === 'string') {
result.end_image = result.end_image.replace('http://', 'https://')
}
return result
}

/**
* returns route context
* @returns {{ max_distance: number, max_duration: number }}
*/
static async getFilterContext() {
const result = await this.query()
.max('distance_meters AS max_distance')
.max('duration_seconds AS max_duration')
.first()

return result
}
}

module.exports = Route
2 changes: 2 additions & 0 deletions server/src/models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const Pokestop = require('./Pokestop')
const Pokemon = require('./Pokemon')
const Portal = require('./Portal')
const Ring = require('./Ring')
const Route = require('./Route')
const ScanCell = require('./ScanCell')
const Session = require('./Session')
const Spawnpoint = require('./Spawnpoint')
Expand All @@ -30,6 +31,7 @@ const scannerModels = {
Pokestop,
Pokemon,
Portal,
Route,
ScanCell,
Spawnpoint,
Weather,
Expand Down
18 changes: 10 additions & 8 deletions server/src/routes/authRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ strategies.forEach((strategy, i) => {
strategy.type === 'discord' || strategy.type === 'telegram' ? 'get' : 'post'
if (strategy.enabled) {
const name = strategy.name ?? `${strategy.type}-${i}`
router[method](
`/${name}`,
passport.authenticate(name, {
failureRedirect: '/',
successRedirect: '/',
}),
)
const callbackOptions = {}
const authenticateOptions = {
failureRedirect: '/',
successRedirect: '/',
}
if (strategy.type === 'discord') {
callbackOptions.prompt = strategy.clientPrompt
}
router[method](`/${name}`, passport.authenticate(name, authenticateOptions))
router[method](`/${name}/callback`, async (req, res, next) =>
passport.authenticate(name, async (err, user, info) => {
passport.authenticate(name, callbackOptions, async (err, user, info) => {
if (err) {
return next(err)
}
Expand Down
5 changes: 3 additions & 2 deletions server/src/routes/rootRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const Fetch = require('../services/Fetch')
const { Event, Db } = require('../services/initialization')
const { version } = require('../../../package.json')
const { log, HELPERS } = require('../services/logger')
const buildDefaultFilters = require('../services/filters/builder/base')

const rootRouter = express.Router()

Expand Down Expand Up @@ -287,10 +288,10 @@ rootRouter.get('/api/settings', async (req, res, next) => {
}
}

serverSettings.defaultFilters = Utility.buildDefaultFilters(
serverSettings.defaultFilters = buildDefaultFilters(
serverSettings.user.perms,
serverSettings.available,
Db.models,
Db,
)

// Backup in case there are Pokemon/Quests/Raids etc that are not in the masterfile
Expand Down
Loading