Fixing base route issues. Fix map scrolling issues on iOS

This commit is contained in:
John Lyon-Smith
2018-05-31 07:20:29 -07:00
parent 62876c94c9
commit 9e55320a21
8 changed files with 95 additions and 30 deletions

View File

@@ -105,8 +105,6 @@ class WorkItemSceneAR extends React.Component {
position: hitResultPosition || defaultPosition, position: hitResultPosition || defaultPosition,
}) })
console.log(hitResultPosition || defaultPosition)
setTimeout(() => { setTimeout(() => {
this.updateInitialRotation() this.updateInitialRotation()
}, 200) }, 200)

View File

@@ -294,7 +294,12 @@ export class Activity extends React.Component {
/> />
<ScrollView style={styles.container}> <ScrollView style={styles.container}>
<View style={styles.panel}> <View style={styles.panel}>
<BoundInput binder={binder} name="resolution" label="Resolution:" /> <BoundInput
binder={binder}
name="resolution"
label="Resolution:"
message="You must supply a resolution for the activity"
/>
</View> </View>
<View style={styles.panel}> <View style={styles.panel}>
<BoundOptionStrip <BoundOptionStrip
@@ -307,10 +312,16 @@ export class Activity extends React.Component {
]} ]}
label="Status:" label="Status:"
name="status" name="status"
message="You must supply a status for the activity"
/> />
</View> </View>
<View style={styles.panel}> <View style={styles.panel}>
<BoundInput binder={binder} name="notes" label="Notes:" /> <BoundInput
binder={binder}
name="notes"
label="Notes:"
message="You must supply notes for the activity"
/>
</View> </View>
<View style={styles.panel}> <View style={styles.panel}>
<FormStaticInput label="Date &amp; Time:" value={dateTime} /> <FormStaticInput label="Date &amp; Time:" value={dateTime} />

View File

@@ -209,6 +209,11 @@ export class WorkItem extends React.Component {
} }
handleRegionChange(region) { handleRegionChange(region) {
if (!this.isMapReady) {
// On iOS we get this after setting the initial region, before the map declared as ready!
return
}
const { latitude, longitude } = region const { latitude, longitude } = region
this.region = region this.region = region

View File

@@ -12,7 +12,7 @@ server {
# Any route that starts with /api/ is for the backend # Any route that starts with /api/ is for the backend
location /api/ { location /api/ {
error_page 502 503 $scheme://$server_name/500.json; error_page 502 503 504 $scheme://$server_name/500.json;
proxy_pass http://127.0.0.1:3006/; proxy_pass http://127.0.0.1:3006/;
proxy_buffering off; proxy_buffering off;

View File

@@ -6,7 +6,11 @@ import { catchAll, TeamRoutes, BaseRoutes } from "."
@autobind @autobind
export class ActivityRoutes extends BaseRoutes { export class ActivityRoutes extends BaseRoutes {
constructor(container) { constructor(container) {
super(container, container.db.Activity) super({
container,
model: container.db.Activity,
nonAdmin: { listItems: true, createItem: true, getItem: true },
})
const app = container.app const app = container.app
@@ -19,6 +23,12 @@ export class ActivityRoutes extends BaseRoutes {
} }
async deleteAllActivities(req, res, next) { async deleteAllActivities(req, res, next) {
const isAdmin = !!req.user.administrator
if (!isAdmin) {
throw createError.Forbidden()
}
const Activity = this.db.Activity const Activity = this.db.Activity
const Team = this.db.Team const Team = this.db.Team

View File

@@ -3,14 +3,23 @@ import createError from "http-errors"
import autobind from "autobind-decorator" import autobind from "autobind-decorator"
import { catchAll } from "." import { catchAll } from "."
// The list of functions you can list in options.nonAdmin is:
//
// listItems
// createItem
// updateItem
// getItem
// deleteItem
@autobind @autobind
export class BaseRoutes { export class BaseRoutes {
constructor(container, model) { constructor(options) {
this.model = model const { container } = options
this.options = options
this.log = container.log this.log = container.log
this.db = container.db this.db = container.db
const basePath = "/" + model.collection.collectionName const basePath = "/" + options.model.collection.collectionName
const app = container.app const app = container.app
app app
@@ -41,7 +50,13 @@ export class BaseRoutes {
} }
async listItems(req, res, next) { async listItems(req, res, next) {
const ItemModel = this.model const isAdmin = !!req.user.administrator
if (!this.options.nonAdmin.listItems && !isAdmin) {
throw createError.Forbidden()
}
const ItemModel = this.options.model
const limit = req.query.limit || 20 const limit = req.query.limit || 20
const skip = req.query.skip || 0 const skip = req.query.skip || 0
const partial = !!req.query.partial const partial = !!req.query.partial
@@ -74,14 +89,14 @@ export class BaseRoutes {
}) })
} }
async createItem(req, res, next) { async createItem(req, res) {
const isAdmin = req.user.administrator const isAdmin = !!req.user.administrator
if (!isAdmin) { if (!this.options.nonAdmin.createItem && !isAdmin) {
return new createError.Forbidden() throw createError.Forbidden()
} }
const ItemModel = this.model const ItemModel = this.options.model
let item = new ItemModel(req.body) let item = new ItemModel(req.body)
const newItem = await item.save() const newItem = await item.save()
@@ -89,11 +104,11 @@ export class BaseRoutes {
res.json(newItem.toClient()) res.json(newItem.toClient())
} }
async updateItem(req, res, next) { async updateItem(req, res) {
const isAdmin = req.user.administrator const isAdmin = !!req.user.administrator
if (!isAdmin) { if (!this.options.nonAdmin.updateItem && !isAdmin) {
return new createError.Forbidden() throw createError.Forbidden()
} }
// Do this here because Mongoose will add it automatically otherwise // Do this here because Mongoose will add it automatically otherwise
@@ -101,11 +116,11 @@ export class BaseRoutes {
throw createError.BadRequest("No _id given in body") throw createError.BadRequest("No _id given in body")
} }
let ItemModel = this.model let ItemModel = this.options.model
let item = await ItemModel.findById(req.body._id) let item = await ItemModel.findById(req.body._id)
if (!item) { if (!item) {
return next(createError.NotFound(`Item with _id ${_id} was not found`)) throw createError.NotFound(`Item with _id ${_id} was not found`)
} }
item.merge(new ItemModel(req.body)) item.merge(new ItemModel(req.body))
@@ -115,8 +130,14 @@ export class BaseRoutes {
res.json(savedItem.toClient()) res.json(savedItem.toClient())
} }
async getItem(req, res, next) { async getItem(req, res) {
const ItemModel = this.model const isAdmin = !!req.user.administrator
if (!this.options.nonAdmin.getItem && !isAdmin) {
throw createError.Forbidden()
}
const ItemModel = this.options.model
const _id = req.params._id const _id = req.params._id
const item = await ItemModel.findById(_id) const item = await ItemModel.findById(_id)
@@ -127,14 +148,14 @@ export class BaseRoutes {
res.json(item.toClient()) res.json(item.toClient())
} }
async deleteItem(req, res, next) { async deleteItem(req, res) {
const isAdmin = req.user.administrator const isAdmin = !!req.user.administrator
if (!isAdmin) { if (!this.options.nonAdmin.deleteItem && !isAdmin) {
return new createError.Forbidden() throw createError.Forbidden()
} }
const ItemModel = this.model const ItemModel = this.options.model
const _id = req.params._id const _id = req.params._id
const item = await ItemModel.remove({ _id }) const item = await ItemModel.remove({ _id })

View File

@@ -8,7 +8,11 @@ import { catchAll, BaseRoutes } from "."
@autobind @autobind
export class TeamRoutes extends BaseRoutes { export class TeamRoutes extends BaseRoutes {
constructor(container) { constructor(container) {
super(container, container.db.Team) super({
container,
model: container.db.Team,
nonAdmin: { listItems: true, getItem: true },
})
container.app container.app
.route("/teams/status") .route("/teams/status")
@@ -19,6 +23,12 @@ export class TeamRoutes extends BaseRoutes {
} }
async getTeamStatus(req, res, next) { async getTeamStatus(req, res, next) {
const isAdmin = !!req.user.administrator
if (!isAdmin) {
throw createError.Forbidden()
}
const Team = this.db.Team const Team = this.db.Team
const Activity = this.db.Activity const Activity = this.db.Activity
let teams = await Team.find({}).exec() let teams = await Team.find({}).exec()

View File

@@ -7,7 +7,11 @@ import { catchAll, BaseRoutes } from "."
@autobind @autobind
export class WorkItemRoutes extends BaseRoutes { export class WorkItemRoutes extends BaseRoutes {
constructor(container) { constructor(container) {
super(container, container.db.WorkItem) super({
container,
model: container.db.WorkItem,
nonAdmin: { listItems: true, getItem: true },
})
const app = container.app const app = container.app
app app
@@ -63,6 +67,12 @@ export class WorkItemRoutes extends BaseRoutes {
} }
async deleteAllWorkItems(req, res, next) { async deleteAllWorkItems(req, res, next) {
const isAdmin = !!req.user.administrator
if (!isAdmin) {
throw createError.Forbidden()
}
const Activity = this.db.Activity const Activity = this.db.Activity
const WorkItem = this.db.WorkItem const WorkItem = this.db.WorkItem
const Team = this.db.Team const Team = this.db.Team