Skip to content

Commit

Permalink
fix: continued implementation
Browse files Browse the repository at this point in the history
co-authored by ianshade <[email protected]>
  • Loading branch information
nytamin committed Oct 18, 2023
1 parent 948bc9b commit 7bb4c61
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 207 deletions.
9 changes: 7 additions & 2 deletions apps/app/src/electron/EverythingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ type ConvertToServerSide<T> = {
: T[K]
}

/** This class is used server-side, to handle requests from the client */
/**
* This class is used server-side, to handle requests from the client
* The methods in here will later be moved away to other Services
*/
export class EverythingService
extends (EventEmitter as new () => TypedEmitter<IPCServerEvents>)
implements ConvertToServerSide<IPCServerMethods>
Expand Down Expand Up @@ -2201,8 +2204,10 @@ export class EverythingService

this._saveUpdates({ appData })
}
async updateProject(arg: { id: string; project: Project }): Promise<void> {
async updateProject(arg: { id: string; project: Project }): Promise<Project> {
this._saveUpdates({ project: arg.project })

return this.storage.getProject()
}
async newRundown(arg: { name: string }): Promise<UndoableResult<Rundown>> {
const rundown = this.storage.newRundown(arg.name)
Expand Down
45 changes: 44 additions & 1 deletion apps/app/src/electron/api/PartService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import EventEmitter from 'node:events'
import { GeneralError } from '@feathersjs/errors'
import { RundownTrigger } from '../../models/rundown/Trigger'
import { ClientEventBus } from '../ClientEventBus'
import { ResourceAny } from '@shared/models'
import { ResourceAny, ResourceId } from '@shared/models'
import { MoveTarget } from '../../lib/util'
import { Part } from '../../models/rundown/Part'
import { ServiceTypes } from '../../ipc/IPCAPI'
import { TimelineObj } from '../../models/rundown/TimelineObj'

export class PartService extends EventEmitter {
constructor(
Expand Down Expand Up @@ -101,4 +102,46 @@ export class PartService extends EventEmitter {
const result = await this.everythingService.duplicatePart(data)
if (!result) throw new GeneralError()
}

async deleteTimelineObj(data: {
rundownId: string
groupId: string
partId: string
timelineObjId: string
}): Promise<void> {
// TODO: access control
const result = await this.everythingService.deleteTimelineObj(data)
if (!result) throw new GeneralError()
}

async insertTimelineObjs(data: {
rundownId: string
groupId: string
partId: string
timelineObjs: TimelineObj[]
target: MoveTarget | null
}): Promise<
{
groupId: string
partId: string
timelineObjId: string
}[]
> {
// TODO: access control
const result = await this.everythingService.insertTimelineObjs(data)
if (!result?.result) throw new GeneralError()
return result.result
}

async addResourcesToTimeline(data: {
rundownId: string
groupId: string
partId: string

layerId: string | null
resourceIds: (ResourceId | ResourceAny)[]
}): Promise<void> {
// TODO: access control
await this.everythingService.addResourcesToTimeline(data)
}
}
5 changes: 5 additions & 0 deletions apps/app/src/electron/api/ProjectService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ export class ProjectService extends EventEmitter {
return await this.everythingService.newProject()
}

async update(id: string, project: Project): Promise<ProjectBase> {
// TODO: access control
return await this.everythingService.updateProject({ id, project })
}

async open(data: { projectId: string }): Promise<void> {
// TODO: access control
return await this.everythingService.openProject(data)
Expand Down
190 changes: 0 additions & 190 deletions apps/app/src/electron/api/RundownService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@ import { Rundown } from '../../models/rundown/Rundown'
import EventEmitter from 'node:events'
import { GeneralError, NotFound } from '@feathersjs/errors'
import { ServiceTypes } from '../../ipc/IPCAPI'
import { RundownTrigger } from '../../models/rundown/Trigger'
import { PartialDeep } from 'type-fest/source/partial-deep'
import { TimelineObj } from '../../models/rundown/TimelineObj'
import { ClientEventBus } from '../ClientEventBus'
import { ResourceAny, ResourceId } from '@shared/models'
import { MoveTarget } from '../../lib/util'

export const RUNDOWN_CHANNEL_PREFIX = 'rundowns/'
interface TimelineObjectUpdate {
Expand Down Expand Up @@ -93,84 +90,6 @@ export class RundownService extends EventEmitter {
return await this.everythingService.isRundownPlaying(data)
}

async setPartTrigger(data: {
rundownId: string
groupId: string
partId: string
trigger: RundownTrigger | null
triggerIndex: number | null
}): Promise<void> {
// TODO: access control
await this.everythingService.setPartTrigger(data)
}

// async stopGroup(data: GroupData): Promise<void> {
// // TODO: access control
// await this.everythingService.stopGroup(data)
// }

// async playGroup(data: GroupData): Promise<void> {
// // TODO: access control
// await this.everythingService.playGroup(data)
// }

// async pauseGroup(data: GroupData): Promise<void> {
// // TODO: access control
// await this.everythingService.pauseGroup(data)
// }

// async playNext(data: GroupData): Promise<void> {
// // TODO: access control
// await this.everythingService.playNext(data)
// }

// async playPrev(data: GroupData): Promise<void> {
// // TODO: access control
// await this.everythingService.playPrev(data)
// }

async deleteTimelineObj(data: {
rundownId: string
groupId: string
partId: string
timelineObjId: string
}): Promise<void> {
// TODO: access control
const result = await this.everythingService.deleteTimelineObj(data)
if (!result) throw new GeneralError()
}

async insertTimelineObjs(data: {
rundownId: string
groupId: string
partId: string
timelineObjs: TimelineObj[]
target: MoveTarget | null
}): Promise<
{
groupId: string
partId: string
timelineObjId: string
}[]
> {
// TODO: access control
const result = await this.everythingService.insertTimelineObjs(data)
if (!result?.result) throw new GeneralError()
return result.result
}

async addResourcesToTimeline(data: {
rundownId: string
groupId: string
partId: string

layerId: string | null
resourceIds: (ResourceId | ResourceAny)[]
}): Promise<void> {
// TODO: access control
await this.everythingService.addResourcesToTimeline(data)
}

async updateTimelineObj(data: TimelineObjectUpdate): Promise<void> {
// TODO: access control
await this.everythingService.updateTimelineObj(data)
Expand All @@ -180,113 +99,4 @@ export class RundownService extends EventEmitter {
// TODO: access control
await this.everythingService.moveTimelineObjToNewLayer(data)
}

// async newPart(data: {
// rundownId: string
// /** The group to create the part into. If null; will create a "transparent group" */
// groupId: string | null

// name: string
// }): Promise<{ partId: string; groupId?: string }> {
// // TODO: access control
// const result = await this.everythingService.newPart(data)
// if (!result?.result) throw new GeneralError()
// return result.result
// }

// async insertParts(data: {
// rundownId: string
// groupId: string | null
// parts: { part: Part; resources: ResourceAny[] }[]
// target: MoveTarget
// }): Promise<
// {
// groupId: string
// partId: string
// }[]
// > {
// // TODO: access control
// const result = await this.everythingService.insertParts(data)
// if (!result?.result) throw new GeneralError()
// return result.result
// }

// async updatePart(data: { rundownId: string; groupId: string; partId: string; part: Partial<Part> }): Promise<void> {
// // TODO: access control
// const result = await this.everythingService.updatePart(data)
// if (!result) throw new GeneralError()
// }

// async newGroup(data: { rundownId: string; name: string }): Promise<string> {
// // TODO: access control
// const result = await this.everythingService.newGroup(data)
// if (!result?.result) throw new GeneralError()
// return result.result
// }

// async insertGroups(data: {
// rundownId: string
// groups: {
// group: Group
// resources: {
// [partId: string]: ResourceAny[]
// }
// }[]
// target: MoveTarget
// }): Promise<
// {
// groupId: string
// }[]
// > {
// // TODO: access control
// const result = await this.everythingService.insertGroups(data)
// if (!result?.result) throw new GeneralError()
// return result.result
// }

// async updateGroup(data: { rundownId: string; groupId: string; group: PartialDeep<Group> }): Promise<void> {
// // TODO: access control
// const result = await this.everythingService.updateGroup(data)
// if (!result) throw new GeneralError()
// }

// async deletePart(data: { rundownId: string; groupId: string; partId: string }): Promise<void> {
// // TODO: access control
// const result = await this.everythingService.deletePart(data)
// if (!result) throw new GeneralError()
// }

// async deleteGroup(data: { rundownId: string; groupId: string }): Promise<void> {
// // TODO: access control
// const result = await this.everythingService.deleteGroup(data)
// if (!result) throw new GeneralError()
// }

// async moveParts(data: {
// parts: { rundownId: string; partId: string }[]
// to: { rundownId: string; groupId: string | null; target: MoveTarget }
// }): Promise<{ partId: string; groupId: string; rundownId: string }[]> {
// // TODO: access control
// const result = await this.everythingService.moveParts(data)
// if (!result?.result) throw new GeneralError()
// return result.result
// }

// async duplicatePart(data: { rundownId: string; groupId: string; partId: string }): Promise<void> {
// // TODO: access control
// const result = await this.everythingService.duplicatePart(data)
// if (!result) throw new GeneralError()
// }

// async moveGroups(data: { rundownId: string; groupIds: string[]; target: MoveTarget }): Promise<void> {
// // TODO: access control
// const result = await this.everythingService.moveGroups(data)
// if (!result) throw new GeneralError()
// }

// async duplicateGroup(data: { rundownId: string; groupId: string }): Promise<void> {
// // TODO: access control
// const result = await this.everythingService.duplicateGroup(data)
// if (!result) throw new GeneralError()
// }
}
31 changes: 24 additions & 7 deletions apps/app/src/ipc/IPCAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import { DefiningArea } from '../lib/triggers/keyDisplay/keyDisplay'
import { type EverythingService } from '../electron/EverythingService'
import { type PartService } from '../electron/api/PartService'
import { type ProjectService } from '../electron/api/ProjectService'
import { ReportingService } from '../electron/api/ReportingService'
import { RundownService } from '../electron/api/RundownService'
import { GroupService } from '../electron/api/GroupService'
import { type ReportingService } from '../electron/api/ReportingService'
import { type RundownService } from '../electron/api/RundownService'
import { type GroupService } from '../electron/api/GroupService'

export const MAX_UNDO_LEDGER_LENGTH = 100

Expand Down Expand Up @@ -66,8 +66,23 @@ export const ClientMethods: ServiceKeyArrays = {
'update',
],
[ServiceName.LEGACY]: [],
[ServiceName.PARTS]: ['play', 'stop', 'pause', 'move', 'duplicate', 'create', 'update', 'remove', 'insert'],
[ServiceName.PROJECTS]: ['create', 'getAll', 'open', 'import', 'export'],
[ServiceName.PARTS]: [
'play',
'stop',
'pause',
'move',
'duplicate',
'create',
'update',
'remove',
'insert',
'setPartTrigger',

'addResourcesToTimeline',
'deleteTimelineObj',
'insertTimelineObjs',
],
[ServiceName.PROJECTS]: ['get', 'create', 'update', 'getAll', 'open', 'import', 'export', 'unsubscribe'],
[ServiceName.REPORTING]: [
'log',
'handleClientError',
Expand All @@ -78,18 +93,20 @@ export const ClientMethods: ServiceKeyArrays = {
[ServiceName.RUNDOWNS]: [
'get',
'create',
'remove',
'rename',
'unsubscribe',
'isPlaying',
'close',
'open',
'setPartTrigger',
// 'pauseGroup',
// 'playGroup',
// 'playNext',
// 'playPrev',
// 'stopGroup',
'updateTimelineObj',
'moveTimelineObjToNewLayer',

// 'newPart',
// 'insertParts',
// 'updatePart',
Expand Down Expand Up @@ -291,7 +308,7 @@ export interface IPCServerMethods {
triggerHandleAutoFill: () => void

updateAppData: (arg: UpdateAppDataOptions) => void
updateProject: (arg: { id: string; project: Project }) => void
updateProject: (arg: { id: string; project: Project }) => Project

newRundown: (arg: { name: string }) => Rundown
deleteRundown: (arg: { rundownId: string }) => void
Expand Down
Loading

0 comments on commit 7bb4c61

Please sign in to comment.