Skip to content

Commit

Permalink
Case pin on floor plan (#874)
Browse files Browse the repository at this point in the history
* feat: refactor to upgrade and generalize pan and zoom capabilities

* feat: using new general pan/zoom for maximized attachment view

* feat: floorplan pin creation on new case- UI and client logic

* feat: floor plan pins saved as a comment

* feat: floor plan pins rendering on case messages view
  • Loading branch information
nbiton authored and franck-boullier committed Sep 13, 2019
1 parent 6557d9c commit 26878fa
Show file tree
Hide file tree
Showing 17 changed files with 528 additions and 127 deletions.
1 change: 1 addition & 0 deletions client/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
--success-green: #99cc33;
--warn-pale-red: #FDCDD1;
--warn-plain-red: #C0000C;
--attention-red: #C72323;
}

.error-red {
Expand Down
33 changes: 32 additions & 1 deletion imports/api/cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ export const createCase = (
solution,
solutionDeadline,
nextSteps,
nextStepsBy
nextStepsBy,
floorPlanPins
},
newUserEmail,
newUserIsOccupant
Expand Down Expand Up @@ -196,6 +197,36 @@ export const createCase = (
}
}

if (floorPlanPins) {
console.log({ unitItem })

const metaData = UnitMetaData.findOne({ bzId: unitItem.id })
const lastFloorPlan = metaData.floorPlanUrls && metaData.floorPlanUrls.slice(-1)[0]
if (lastFloorPlan && !lastFloorPlan.disabled) {
const payload = {
comment: `[!floorPlan(${lastFloorPlan.id})]\n${floorPlanPins.map(({ x, y }) => `${x.toFixed(1)},${y.toFixed(1)}`).join(';')}`,
api_key: creatorUser.bugzillaCreds.apiKey
}

try {
// Creating the comment
const createData = callAPI('post', `/rest/bug/${newCaseId}/comment`, payload, false, true)
if (createData.data.error) {
throw new Meteor.Error(createData.data.error)
}
} catch (e) {
logger.error({
user: creatorUser._id,
method: `${collectionName}.insert`,
args: [params],
step: 'post /rest/bug/{id}/comment adding floor plan',
error: e
})
throw new Meteor.Error(`API Error: ${e.response ? e.response.data.message : e.message}`)
}
}
}

try {
const resp = callAPI('get', idUrlTemplate(newCaseId), { api_key: process.env.BUGZILLA_ADMIN_KEY }, false, true)
const caseItem = factoryOptions.dataResolver(resp.data)[0]
Expand Down
5 changes: 3 additions & 2 deletions imports/api/unit-meta-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Meteor.methods({

UnitMetaData.update({ _id: id }, { $set: unitFields })
},
[`${collectionName}.updateFloorPlan`] (id, floorPlanUrl) {
[`${collectionName}.updateFloorPlan`] (id, floorPlanUrl, dimensions) {
const metaData = UnitMetaData.findOne({ _id: id })
if (!metaData) {
throw new Meteor.Error(`No unit found for id ${id}`)
Expand All @@ -125,7 +125,8 @@ Meteor.methods({
url: floorPlanUrl,
addedBy: Meteor.userId(),
addedAt: new Date(),
id: randToken.generate(17)
id: randToken.generate(17),
dimensions
}
}
})
Expand Down
3 changes: 2 additions & 1 deletion imports/api/units.js
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,8 @@ if (Meteor.isServer) {
bzId: 1,
displayName: 1,
unitType: 1,
ownerIds: 1
ownerIds: 1,
floorPlanUrls: 1
}),
withRolesData(rolesProjByOwnership, rolesSelectionByOwnership)
]
Expand Down
27 changes: 19 additions & 8 deletions imports/state/actions/unit-floor-plan.actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@ export const UPLOAD_FLOOR_PLAN_COMPLETED = 'upload_unit_floor_plan_completed'
export const CHANGE_FLOOR_PLAN_URL = 'change_unit_floor_plan_url'
export const DISABLE_FLOOR_PLAN = 'disable_unit_floor_plan'

export type Dimensions = {
width: number,
height: number
}

export type UnitFloorPlanInitAction = {
type: string,
preview: string,
file: File,
unitMongoId: string
unitMongoId: string,
dimensions: Dimensions
}

export type UnitFloorPlanProcessAction = {
Expand All @@ -21,35 +27,39 @@ export type UnitFloorPlanProcessAction = {
file?: File,
preview?: string,
percent?: number,
dimensions?: Dimensions,
error?: {}
}

export type UnitFloorPlanCompleteAction = {
type: string,
unitMongoId: string,
url: string
url: string,
dimensions: Dimensions
}

export type UnitFloorPlanDisableAction = {
type: string,
unitMongoId: string
}

export function uploadFloorPlan (unitMongoId: string, preview: string, file: File): UnitFloorPlanInitAction {
export function uploadFloorPlan (unitMongoId: string, preview: string, file: File, dimensions: Dimensions): UnitFloorPlanInitAction {
return {
type: UPLOAD_FLOOR_PLAN,
unitMongoId,
preview,
file
file,
dimensions
}
}

export function uploadFloorPlanStarted (unitMongoId: string, preview: string, file: File): UnitFloorPlanProcessAction {
export function uploadFloorPlanStarted (unitMongoId: string, preview: string, file: File, dimensions: Dimensions): UnitFloorPlanProcessAction {
return {
type: UPLOAD_FLOOR_PLAN_STARTED,
unitMongoId,
preview,
file
file,
dimensions
}
}

Expand All @@ -76,11 +86,12 @@ export function uploadFloorPlanCompleted (unitMongoId: string): UnitFloorPlanPro
}
}

export function changeFloorPlanUrl (unitMongoId: string, url: string): UnitFloorPlanCompleteAction {
export function changeFloorPlanUrl (unitMongoId: string, url: string, dimensions: Dimensions): UnitFloorPlanCompleteAction {
return {
type: CHANGE_FLOOR_PLAN_URL,
unitMongoId,
url
url,
dimensions
}
}

Expand Down
2 changes: 1 addition & 1 deletion imports/state/epics/change-unit-floor-plan-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { genericErrorOccurred } from '../../ui/general-actions'
export const changeUnitFloorPlanUrl = fallibleMethodCaller({
actionType: CHANGE_FLOOR_PLAN_URL,
methodName: `${collectionName}.updateFloorPlan`,
argTranslator: ({ unitMongoId, url }) => [unitMongoId, url],
argTranslator: ({ unitMongoId, url, dimensions }) => [unitMongoId, url, dimensions],
actionGenerators: {
errorGen: (error, action) => genericErrorOccurred(
`Error occurred while trying to update the floor plan URL for unit ${action.unitMongoId}: ${error.message}`
Expand Down
4 changes: 2 additions & 2 deletions imports/state/epics/upload-unit-floor-plan.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import {
import type { UnitFloorPlanInitAction } from '../actions/unit-floor-plan.actions'

export const uploadUnitFloorPlan = fileUploadProcessor < UnitFloorPlanInitAction > (UPLOAD_FLOOR_PLAN, {
init: action => uploadFloorPlanStarted(action.unitMongoId, action.preview, action.file),
init: action => uploadFloorPlanStarted(action.unitMongoId, action.preview, action.file, action.dimensions),
progress: (action, percent) => uploadFloorPlanProgress(action.unitMongoId, percent),
error: (action, error) => uploadFloorPlanError(action.unitMongoId, error),
complete: (action, url) => [
uploadFloorPlanCompleted(action.unitMongoId),
changeFloorPlanUrl(action.unitMongoId, url)
changeFloorPlanUrl(action.unitMongoId, url, action.dimensions)
]
})
6 changes: 4 additions & 2 deletions imports/state/reducers/unit-floor-plan-upload-state.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @flow
import type { UnitFloorPlanProcessAction } from '../actions/unit-floor-plan.actions'
import type { Dimensions, UnitFloorPlanProcessAction } from '../actions/unit-floor-plan.actions'
import {
UPLOAD_FLOOR_PLAN_COMPLETED,
UPLOAD_FLOOR_PLAN_ERROR,
Expand All @@ -11,6 +11,7 @@ type Process = {
unitMongoId: string,
preview: string,
percent: number,
dimensions: ?Dimensions,
error?: {}
}

Expand All @@ -26,7 +27,8 @@ export default function (state: State = [], action: UnitFloorPlanProcessAction):
const newProcess = {
unitMongoId: action.unitMongoId,
percent: 0,
preview: action.preview || ''
preview: action.preview || '',
dimensions: action.dimensions
}
if (processIndex === -1) {
newState.push(newProcess)
Expand Down
Loading

0 comments on commit 26878fa

Please sign in to comment.