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

WIP: Handle occlusion and the 'visible' key in ljsonv3 #137

Open
wants to merge 5 commits into
base: ts_react
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 4 additions & 6 deletions src/ts/app/backend/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,25 +66,23 @@ export interface Backend {
fetchGeometry(assetId: string): Promise<THREE.BufferGeometry>

/**
* Return the remote data for landmarks for an asset/template combination
* Return the remote data for landmarks for an asset
*
* @param {String} assetId
* @param {String} type [template name]
* @return {Promise}
* @resolve {Object} [Parsed JSON]
*/
fetchLandmarkGroup(assetId: string, group:string): Promise<LJSONFile>
fetchLandmarkGroups(assetId: string): Promise<LJSONFile>

/**
* Saves the json data remotely for landmarks for an asset/template combination,
* Saves the json data remotely for landmarks for an asset,
* resolving with any value marks success, rejection is an error
*
* @param {String} assetId
* @param {String} type [template name]
* @param {Object} json
* @return {Promise}
* @resolve {}
*/
saveLandmarkGroup(assetId: string, group:string, object:Object): Promise<{}>
saveLandmarkGroups(assetId: string, object:Object): Promise<{}>

}
17 changes: 12 additions & 5 deletions src/ts/app/backend/dropbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,22 +488,29 @@ export class Dropbox implements Backend {
return geometry
}

fetchLandmarkGroup(id: string, group: string) {
fetchLandmarkGroups(id: string) {

const path = `${this._assetsPath}/landmarks/${id}_${group}.ljson`
const path = `${this._assetsPath}/landmarks/${id}.ljson`
const dim = this.mode === 'mesh' ? 3 : 2
return new Promise((resolve) => {
this.download(path).then((data) => {
resolve(JSON.parse(data))
}, () => {
resolve(this._templates[group].emptyLJSON(dim))
const emptyLJSON = {
groups: {},
version: 3
}
for (let group in this._templates) {
emptyLJSON.groups[group] = this._templates[group].emptyLJSONGroup(dim)
}
resolve(emptyLJSON)
})
})
}

saveLandmarkGroup(id: string, group: string, json: Object) {
saveLandmarkGroups(id: string, json: Object) {
const headers = this.headers(),
path = `${this._assetsPath}/landmarks/${id}_${group}.ljson`
path = `${this._assetsPath}/landmarks/${id}.ljson`

return putJSON(
`${CONTENTS_URL}/files_put/auto${path}`, {data: json, headers})
Expand Down
19 changes: 14 additions & 5 deletions src/ts/app/backend/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class Server implements Backend {

url: string
demoMode = false
version = 2
version = 3
httpAuth = false

constructor(url: string) {
Expand All @@ -102,6 +102,10 @@ export class Server implements Backend {
return `/api/v${this.version}/`
}

apiHeaderForVersion(apiVersion: number) {
return `/api/v${apiVersion}/`
}

map(url: string) {
if (this.demoMode) {
// demoMode so we ignore the server url
Expand Down Expand Up @@ -132,6 +136,11 @@ export class Server implements Backend {
return this.fetchJSON('mode')
}

fetchModeForVersion(apiVersion: number) {
const url = this.url + this.apiHeaderForVersion(apiVersion) + 'mode'
return getJSON(url, {auth: this.httpAuth})
}

fetchTemplates() {
return this.fetchJSON('templates')
}
Expand All @@ -144,12 +153,12 @@ export class Server implements Backend {
return this.fetchJSON(`collections/${collectionId}`)
}

fetchLandmarkGroup(id: string, type: string) {
return getJSON(this.map(`landmarks/${id}/${type}`), {auth: this.httpAuth})
fetchLandmarkGroups(id: string) {
return getJSON(this.map(`landmarks/json/${id}`), {auth: this.httpAuth})
}

saveLandmarkGroup(id: string, group: string, json: Object) {
return putJSON(this.map(`landmarks/${id}/${group}`), {
saveLandmarkGroups(id: string, json: Object) {
return putJSON(this.map(`landmarks/json/${id}`), {
data: json,
auth: this.httpAuth
})
Expand Down
44 changes: 23 additions & 21 deletions src/ts/app/model/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as Backbone from 'backbone'
import Tracker from '../lib/tracker'
import * as AssetSource from './assetsource'
import * as Asset from './asset'
import { LandmarkGroup, LandmarkGroupTracker, landmarkGroupTrackerFactory } from './landmark'
import { LandmarkGroup, LandmarkGroups, LandmarkGroupTracker } from './landmark'
import Modal from '../view/modal'
import { Backend } from '../backend'

Expand Down Expand Up @@ -58,6 +58,10 @@ export class App extends Backbone.Model {
return this.get('landmarks')
}

get landmarkGroups(): LandmarkGroups {
return this.get('landmarkGroups')
}

set isConnectivityOn(isConnectivityOn: boolean) {
this.set('connectivityOn', isConnectivityOn)
}
Expand Down Expand Up @@ -303,25 +307,23 @@ export class App extends Backbone.Model {
})
}

landmarkGroupTrackerForAssetAndTemplate(assetId: string, template: string): LandmarkGroupTracker {
landmarkGroupTrackersForAsset(assetId: string): {[template: string]: LandmarkGroupTracker} {
const trackers = this.landmarkGroupTrackers
if (!trackers[assetId]) {
trackers[assetId] = {}
}

if (!trackers[assetId][template]) {
trackers[assetId][template] = landmarkGroupTrackerFactory()
}

return trackers[assetId][template]
return trackers[assetId]
}

reloadLandmarks() {
if (this.landmarks && this.asset) {
this.autoSaveWrapper(() => {
this.set('landmarkGroups', null)
this.set('landmarks', null)
this.loadLandmarksPromise().then((lms) => {
this.set('landmarks', lms)
this.loadLandmarksPromise().then((lmGroups) => {
this.set('landmarkGroups', lmGroups)
this.set('landmarks', lmGroups.groups[this.activeTemplate])
})
})
}
Expand Down Expand Up @@ -363,16 +365,14 @@ export class App extends Backbone.Model {
}

loadLandmarksPromise() {
return this.backend.fetchLandmarkGroup(
this.asset.id,
this.activeTemplate
return this.backend.fetchLandmarkGroups(
this.asset.id
).then(json => {
return LandmarkGroup.parse(
return new LandmarkGroups(
json,
this.asset.id,
this.activeTemplate,
this.backend,
this.landmarkGroupTrackerForAssetAndTemplate(this.asset.id, this.activeTemplate)
this.landmarkGroupTrackersForAsset(this.asset.id)
)
}, () => {
console.log('Error in fetching landmark JSON file')
Expand All @@ -386,13 +386,14 @@ export class App extends Backbone.Model {
// if both come true, then set the landmarks
return Promise.all([this.loadLandmarksPromise(),
loadAssetPromise]).then((args) => {
const landmarks = args[0]
const landmarkGroups = args[0]
console.log('landmarks are loaded and the asset is at a suitable ' +
'state to display')
// now we know that this is resolved we set the landmarks on the
// app. This way we know the landmarks will always be set with a
// valid asset.
this.set('landmarks', landmarks)
this.set('landmarkGroups', landmarkGroups)
this.set('landmarks', landmarkGroups.groups[this.activeTemplate])
})
}

Expand All @@ -403,6 +404,7 @@ export class App extends Backbone.Model {
// applicable) and asset data are present
if (newAssetPromise) {
this.set('landmarks', null)
this.set('landmarkGroups', null)
return this._promiseLandmarksWithAsset(newAssetPromise)
}
}
Expand Down Expand Up @@ -431,15 +433,15 @@ export class App extends Backbone.Model {

reloadLandmarksFromPrevious() {
const lms = this.landmarks
const template = this.activeTemplate
if (lms) {
const as = this.assetSource
if (this.assetSource.hasPredecessor) {
this.backend.fetchLandmarkGroup(
as.assets()[as.assetIndex - 1].id,
this.activeTemplate
this.backend.fetchLandmarkGroups(
as.assets()[as.assetIndex - 1].id
).then((json) => {
lms.tracker.recordState(lms.toJSON())
lms.restore(json)
lms.restore(json.groups[template])
lms.tracker.recordState(lms.toJSON(), false, true)
}, () => {
console.log('Error in fetching landmark JSON file')
Expand Down
Loading