refact: generalized back end structs (#1)
* refact: generalized back end structs * refact: fixed front end type, removed dead code * removed test image folder * refact: removed dead structs
This commit is contained in:
parent
83249efc23
commit
c49f8e4d07
@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
document "textualize/core/Document"
|
document "textualize/core/Document"
|
||||||
session "textualize/core/Session"
|
session "textualize/core/Session"
|
||||||
|
"textualize/entities"
|
||||||
storage "textualize/storage"
|
storage "textualize/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -26,10 +27,10 @@ func (a *App) Startup(ctx context.Context) {
|
|||||||
a.Context = ctx
|
a.Context = ctx
|
||||||
localUserData := storage.GetDriver().ReadUserData()
|
localUserData := storage.GetDriver().ReadUserData()
|
||||||
session.InitializeModule(session.Session{
|
session.InitializeModule(session.Session{
|
||||||
User: session.User(localUserData),
|
User: entities.User(localUserData),
|
||||||
})
|
})
|
||||||
|
|
||||||
document.InitizeModule()
|
document.InitializeModule()
|
||||||
|
|
||||||
fmt.Println(localUserData)
|
fmt.Println(localUserData)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,13 +1,9 @@
|
|||||||
package consts
|
package consts
|
||||||
|
|
||||||
type Language struct {
|
import "textualize/entities"
|
||||||
DisplayName string
|
|
||||||
ProcessCode string
|
|
||||||
TranslateCode string
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetSuppportedLanguages() []Language {
|
func GetSuppportedLanguages() []entities.Language {
|
||||||
return []Language{
|
return []entities.Language{
|
||||||
{
|
{
|
||||||
DisplayName: "English",
|
DisplayName: "English",
|
||||||
ProcessCode: "eng",
|
ProcessCode: "eng",
|
||||||
|
|||||||
@ -1,36 +1,19 @@
|
|||||||
package document
|
package document
|
||||||
|
|
||||||
import (
|
import (
|
||||||
consts "textualize/core/Consts"
|
"textualize/entities"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Entity struct {
|
type Entity entities.Document
|
||||||
Id string
|
|
||||||
GroupId string
|
|
||||||
Name string
|
|
||||||
Path string
|
|
||||||
ProjectId string
|
|
||||||
Areas []Area
|
|
||||||
DefaultLanguage consts.Language
|
|
||||||
}
|
|
||||||
|
|
||||||
type Area struct {
|
type Area entities.Area
|
||||||
Id string
|
|
||||||
Name string
|
|
||||||
StartX int
|
|
||||||
StartY int
|
|
||||||
EndX int
|
|
||||||
EndY int
|
|
||||||
Language consts.Language
|
|
||||||
Order int
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *Entity) AddArea(a Area) {
|
func (e *Entity) AddArea(a entities.Area) {
|
||||||
e.Areas = append(e.Areas, a)
|
e.Areas = append(e.Areas, a)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Entity) GetAreaById(areaId string) *Area {
|
func (e *Entity) GetAreaById(areaId string) *entities.Area {
|
||||||
var foundArea *Area
|
var foundArea *entities.Area
|
||||||
|
|
||||||
for index, a := range e.Areas {
|
for index, a := range e.Areas {
|
||||||
if a.Id == areaId {
|
if a.Id == areaId {
|
||||||
|
|||||||
@ -1,18 +1,10 @@
|
|||||||
package document
|
package document
|
||||||
|
|
||||||
type Group struct {
|
import "textualize/entities"
|
||||||
Id string
|
|
||||||
ParentId string
|
|
||||||
ProjectId string
|
|
||||||
Name string
|
|
||||||
Order int
|
|
||||||
}
|
|
||||||
|
|
||||||
type GroupCollection struct {
|
type Group entities.Group
|
||||||
Id string
|
|
||||||
Groups []Group
|
type GroupCollection entities.GroupCollection
|
||||||
ProjectId string
|
|
||||||
}
|
|
||||||
|
|
||||||
var groupCollectionInstance *GroupCollection
|
var groupCollectionInstance *GroupCollection
|
||||||
|
|
||||||
@ -29,12 +21,12 @@ func SetGroupCollection(collection GroupCollection) *GroupCollection {
|
|||||||
return groupCollectionInstance
|
return groupCollectionInstance
|
||||||
}
|
}
|
||||||
|
|
||||||
func (collection *GroupCollection) AddDocumentGroup(group Group) {
|
func (collection *GroupCollection) AddDocumentGroup(group entities.Group) {
|
||||||
collection.Groups = append(collection.Groups, group)
|
collection.Groups = append(collection.Groups, group)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (collection *GroupCollection) GetGroupById(groupId string) *Group {
|
func (collection *GroupCollection) GetGroupById(groupId string) *entities.Group {
|
||||||
var foundGroup *Group
|
var foundGroup *entities.Group
|
||||||
|
|
||||||
for index, g := range collection.Groups {
|
for index, g := range collection.Groups {
|
||||||
if g.Id == groupId {
|
if g.Id == groupId {
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
package document
|
package document
|
||||||
|
|
||||||
func InitizeModule() {
|
import "textualize/entities"
|
||||||
|
|
||||||
|
func InitializeModule() {
|
||||||
GetDocumentCollection()
|
GetDocumentCollection()
|
||||||
GetGroupCollection()
|
GetGroupCollection()
|
||||||
}
|
}
|
||||||
@ -9,7 +11,7 @@ func createTestData() {
|
|||||||
documentCollection := GetDocumentCollection()
|
documentCollection := GetDocumentCollection()
|
||||||
documentGroupCollection := GetGroupCollection()
|
documentGroupCollection := GetGroupCollection()
|
||||||
|
|
||||||
documentGroupCollection.AddDocumentGroup(Group{
|
documentGroupCollection.AddDocumentGroup(entities.Group{
|
||||||
Id: "XYZ",
|
Id: "XYZ",
|
||||||
Name: "Test Group One",
|
Name: "Test Group One",
|
||||||
})
|
})
|
||||||
|
|||||||
@ -1,42 +1,9 @@
|
|||||||
package document
|
package document
|
||||||
|
|
||||||
type ProcessedBoundingBox struct {
|
import "textualize/entities"
|
||||||
X0 int32
|
|
||||||
Y0 int32
|
|
||||||
X1 int32
|
|
||||||
Y1 int32
|
|
||||||
}
|
|
||||||
|
|
||||||
type ProcessedSymbol struct {
|
|
||||||
Text string
|
|
||||||
Confidence float32
|
|
||||||
BoundingBox ProcessedBoundingBox
|
|
||||||
}
|
|
||||||
|
|
||||||
type ProcessedWord struct {
|
|
||||||
Id string
|
|
||||||
FullText string
|
|
||||||
Symbols []ProcessedSymbol
|
|
||||||
Confidence float32
|
|
||||||
Direction string
|
|
||||||
BoundingBox ProcessedBoundingBox
|
|
||||||
}
|
|
||||||
|
|
||||||
type ProcessedLine struct {
|
|
||||||
FullText string
|
|
||||||
Words []ProcessedWord
|
|
||||||
}
|
|
||||||
|
|
||||||
type ProcessedArea struct {
|
|
||||||
Id string
|
|
||||||
DocumentId string
|
|
||||||
FullText string
|
|
||||||
Order int
|
|
||||||
Lines []ProcessedLine
|
|
||||||
}
|
|
||||||
|
|
||||||
type ProcessedAreaCollection struct {
|
type ProcessedAreaCollection struct {
|
||||||
Areas []ProcessedArea
|
Areas []entities.ProcessedArea
|
||||||
}
|
}
|
||||||
|
|
||||||
var processedAreaCollectionInstnace *ProcessedAreaCollection
|
var processedAreaCollectionInstnace *ProcessedAreaCollection
|
||||||
@ -52,12 +19,12 @@ func SetProcessedAreaCollection(collection ProcessedAreaCollection) {
|
|||||||
processedAreaCollectionInstnace = &collection
|
processedAreaCollectionInstnace = &collection
|
||||||
}
|
}
|
||||||
|
|
||||||
func (collection *ProcessedAreaCollection) AddProcessedArea(area ProcessedArea) {
|
func (collection *ProcessedAreaCollection) AddProcessedArea(area entities.ProcessedArea) {
|
||||||
collection.Areas = append(collection.Areas, area)
|
collection.Areas = append(collection.Areas, area)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (collection *ProcessedAreaCollection) GetAreasByDocumentId(id string) []*ProcessedArea {
|
func (collection *ProcessedAreaCollection) GetAreasByDocumentId(id string) []*entities.ProcessedArea {
|
||||||
var foundAreas []*ProcessedArea
|
var foundAreas []*entities.ProcessedArea
|
||||||
|
|
||||||
for index, a := range collection.Areas {
|
for index, a := range collection.Areas {
|
||||||
if a.DocumentId == id {
|
if a.DocumentId == id {
|
||||||
@ -68,8 +35,8 @@ func (collection *ProcessedAreaCollection) GetAreasByDocumentId(id string) []*Pr
|
|||||||
return foundAreas
|
return foundAreas
|
||||||
}
|
}
|
||||||
|
|
||||||
func (collection *ProcessedAreaCollection) GetAreaById(areaId string) *ProcessedArea {
|
func (collection *ProcessedAreaCollection) GetAreaById(areaId string) *entities.ProcessedArea {
|
||||||
var foundArea *ProcessedArea
|
var foundArea *entities.ProcessedArea
|
||||||
|
|
||||||
for index, a := range collection.Areas {
|
for index, a := range collection.Areas {
|
||||||
if a.Id == areaId {
|
if a.Id == areaId {
|
||||||
|
|||||||
@ -1,13 +1,9 @@
|
|||||||
package document
|
package document
|
||||||
|
|
||||||
type UserMarkdown struct {
|
import "textualize/entities"
|
||||||
Id string
|
|
||||||
DocumentId string
|
|
||||||
Value string
|
|
||||||
}
|
|
||||||
|
|
||||||
type UserMarkdownCollection struct {
|
type UserMarkdownCollection struct {
|
||||||
Values []UserMarkdown
|
Values []entities.UserMarkdown
|
||||||
}
|
}
|
||||||
|
|
||||||
var userMarkdownCollection *UserMarkdownCollection
|
var userMarkdownCollection *UserMarkdownCollection
|
||||||
@ -24,8 +20,8 @@ func SetUserMarkdownCollection(collection UserMarkdownCollection) {
|
|||||||
userMarkdownCollection = &collection
|
userMarkdownCollection = &collection
|
||||||
}
|
}
|
||||||
|
|
||||||
func (collection *UserMarkdownCollection) GetUserMarkdownByDocumentId(documentId string) *UserMarkdown {
|
func (collection *UserMarkdownCollection) GetUserMarkdownByDocumentId(documentId string) *entities.UserMarkdown {
|
||||||
var foundUserMarkdown *UserMarkdown
|
var foundUserMarkdown *entities.UserMarkdown
|
||||||
|
|
||||||
for index, m := range collection.Values {
|
for index, m := range collection.Values {
|
||||||
if m.DocumentId == documentId {
|
if m.DocumentId == documentId {
|
||||||
@ -37,12 +33,12 @@ func (collection *UserMarkdownCollection) GetUserMarkdownByDocumentId(documentId
|
|||||||
return foundUserMarkdown
|
return foundUserMarkdown
|
||||||
}
|
}
|
||||||
|
|
||||||
func (collection *UserMarkdownCollection) AddUserMarkdown(userMarkdown UserMarkdown) UserMarkdown {
|
func (collection *UserMarkdownCollection) AddUserMarkdown(userMarkdown entities.UserMarkdown) entities.UserMarkdown {
|
||||||
collection.Values = append(collection.Values, userMarkdown)
|
collection.Values = append(collection.Values, userMarkdown)
|
||||||
return userMarkdown
|
return userMarkdown
|
||||||
}
|
}
|
||||||
|
|
||||||
func (collection *UserMarkdownCollection) UpdateUserMarkdown(userMarkdown UserMarkdown) UserMarkdown {
|
func (collection *UserMarkdownCollection) UpdateUserMarkdown(userMarkdown entities.UserMarkdown) entities.UserMarkdown {
|
||||||
currentUserMarkdown := collection.GetUserMarkdownByDocumentId(userMarkdown.DocumentId)
|
currentUserMarkdown := collection.GetUserMarkdownByDocumentId(userMarkdown.DocumentId)
|
||||||
|
|
||||||
if currentUserMarkdown != nil {
|
if currentUserMarkdown != nil {
|
||||||
|
|||||||
@ -1,8 +1,5 @@
|
|||||||
package session
|
package session
|
||||||
|
|
||||||
type Organization struct {
|
import "textualize/entities"
|
||||||
Id string
|
|
||||||
Name string
|
type Organization entities.Organization
|
||||||
LogoPath string
|
|
||||||
Users []User
|
|
||||||
}
|
|
||||||
|
|||||||
@ -1,18 +1,9 @@
|
|||||||
package session
|
package session
|
||||||
|
|
||||||
import (
|
import (
|
||||||
consts "textualize/core/Consts"
|
"textualize/entities"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Project struct {
|
type Project entities.Project
|
||||||
Id string
|
|
||||||
OrganizationId string
|
|
||||||
Name string
|
|
||||||
Settings ProjectSettings
|
|
||||||
}
|
|
||||||
|
|
||||||
type ProjectSettings struct {
|
type ProjectSettings entities.ProjectSettings
|
||||||
DefaultProcessLanguage consts.Language
|
|
||||||
DefaultTranslateTargetLanguage consts.Language
|
|
||||||
IsHosted bool
|
|
||||||
}
|
|
||||||
|
|||||||
@ -1,10 +1,8 @@
|
|||||||
package session
|
package session
|
||||||
|
|
||||||
type Session struct {
|
import "textualize/entities"
|
||||||
Project Project
|
|
||||||
Organization Organization
|
type Session entities.Session
|
||||||
User User
|
|
||||||
}
|
|
||||||
|
|
||||||
var sessionInstance *Session
|
var sessionInstance *Session
|
||||||
|
|
||||||
@ -22,7 +20,7 @@ func InitializeModule(newSession Session) *Session {
|
|||||||
return sessionInstance
|
return sessionInstance
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Session) UpdateCurrentUser(updatedUser User) User {
|
func (s *Session) UpdateCurrentUser(updatedUser entities.User) entities.User {
|
||||||
s.User = User(updatedUser)
|
s.User = entities.User(updatedUser)
|
||||||
return s.User
|
return s.User
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
package storage
|
package entities
|
||||||
|
|
||||||
type DocumentCollection struct {
|
type DocumentCollection struct {
|
||||||
Documents []Document `json:"documents"`
|
Documents []Document `json:"documents"`
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package storage
|
package entities
|
||||||
|
|
||||||
type Group struct {
|
type Group struct {
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package storage
|
package entities
|
||||||
|
|
||||||
type Language struct {
|
type Language struct {
|
||||||
DisplayName string `json:"displayName"`
|
DisplayName string `json:"displayName"`
|
||||||
8
entities/Organization.go
Normal file
8
entities/Organization.go
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package entities
|
||||||
|
|
||||||
|
type Organization struct {
|
||||||
|
Id string `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
LogoPath string `json:"logoPath"`
|
||||||
|
Users []User `json:"users"`
|
||||||
|
}
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package storage
|
package entities
|
||||||
|
|
||||||
type ProcessedBoundingBox struct {
|
type ProcessedBoundingBox struct {
|
||||||
X0 int32 `json:"x0"`
|
X0 int32 `json:"x0"`
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package storage
|
package entities
|
||||||
|
|
||||||
type Project struct {
|
type Project struct {
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
7
entities/Session.go
Normal file
7
entities/Session.go
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
package entities
|
||||||
|
|
||||||
|
type Session struct {
|
||||||
|
Project Project `json:"project"`
|
||||||
|
Organization Organization `json:"organization"`
|
||||||
|
User User `json:"user"`
|
||||||
|
}
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package storage
|
package entities
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
11
entities/UserMarkdown.go
Normal file
11
entities/UserMarkdown.go
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
package entities
|
||||||
|
|
||||||
|
type UserMarkdown struct {
|
||||||
|
Id string `json:"id"`
|
||||||
|
DocumentId string `json:"documentId"`
|
||||||
|
Value string `json:"value"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type UserMarkdownCollection struct {
|
||||||
|
Values []UserMarkdown `json:"values"`
|
||||||
|
}
|
||||||
@ -1,12 +1,12 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { ipc } from '../../wailsjs/wailsjs/go/models'
|
import { entities } from '../../wailsjs/wailsjs/go/models'
|
||||||
import classNames from '../../utils/classNames'
|
import classNames from '../../utils/classNames'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
areas: ipc.Area[]
|
areas: entities.Area[]
|
||||||
processedArea?: ipc.ProcessedArea
|
processedArea?: entities.ProcessedArea
|
||||||
zoomLevel: number
|
zoomLevel: number
|
||||||
setWordToEdit: (props: { word: ipc.ProcessedWord, areaId: string }) => void
|
setWordToEdit: (props: { word: entities.ProcessedWord, areaId: string }) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
const AreaTextPreview = ({ areas, processedArea, zoomLevel, setWordToEdit }: Props) => {
|
const AreaTextPreview = ({ areas, processedArea, zoomLevel, setWordToEdit }: Props) => {
|
||||||
|
|||||||
@ -1,15 +1,15 @@
|
|||||||
import React, { useRef } from 'react'
|
import React, { useRef } from 'react'
|
||||||
import { ipc } from '../../wailsjs/wailsjs/go/models'
|
import { ipc, entities } from '../../wailsjs/wailsjs/go/models'
|
||||||
import classNames from '../../utils/classNames'
|
import classNames from '../../utils/classNames'
|
||||||
import onEnterHandler from '../../utils/onEnterHandler'
|
import onEnterHandler from '../../utils/onEnterHandler'
|
||||||
import { useProject } from '../../context/Project/provider'
|
import { useProject } from '../../context/Project/provider'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
zoomLevel: number
|
zoomLevel: number
|
||||||
processedArea?: ipc.ProcessedArea
|
processedArea?: entities.ProcessedArea
|
||||||
wordToEdit?: ipc.ProcessedWord
|
wordToEdit?: entities.ProcessedWord
|
||||||
setWordToEdit: (props?: { word: ipc.ProcessedWord, areaId: string }) => void
|
setWordToEdit: (props?: { word: entities.ProcessedWord, areaId: string }) => void
|
||||||
setHoveredProcessedArea: (area?: ipc.ProcessedArea) => void
|
setHoveredProcessedArea: (area?: entities.ProcessedArea) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
const EditProcessedWord = ({ setWordToEdit, zoomLevel, wordToEdit, processedArea, setHoveredProcessedArea }: Props) => {
|
const EditProcessedWord = ({ setWordToEdit, zoomLevel, wordToEdit, processedArea, setHoveredProcessedArea }: Props) => {
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import React, { WheelEvent, useEffect, useRef, useState } from 'react'
|
import React, { WheelEvent, useEffect, useRef, useState } from 'react'
|
||||||
import { useProject } from '../../context/Project/provider'
|
import { useProject } from '../../context/Project/provider'
|
||||||
import { ipc } from '../../wailsjs/wailsjs/go/models'
|
import { entities } from '../../wailsjs/wailsjs/go/models'
|
||||||
import createUiCanvasInteractions from './createUiCanvasInteractions'
|
import createUiCanvasInteractions from './createUiCanvasInteractions'
|
||||||
import processImageArea from '../../useCases/processImageArea'
|
import processImageArea from '../../useCases/processImageArea'
|
||||||
import AreaTextPreview from './AreaTextPreview'
|
import AreaTextPreview from './AreaTextPreview'
|
||||||
@ -30,8 +30,8 @@ const UiCanvas = (props: Props) => {
|
|||||||
} = useProject()
|
} = useProject()
|
||||||
const canvas = useRef<HTMLCanvasElement>(null)
|
const canvas = useRef<HTMLCanvasElement>(null)
|
||||||
const [hoverOverAreaId, setHoverOverAreaId] = useState('')
|
const [hoverOverAreaId, setHoverOverAreaId] = useState('')
|
||||||
const [wordToEdit, setWordToEdit] = useState<{ word: ipc.ProcessedWord, areaId: string } | undefined>()
|
const [wordToEdit, setWordToEdit] = useState<{ word: entities.ProcessedWord, areaId: string } | undefined>()
|
||||||
const [hoveredProcessedArea, setHoveredProcessedArea] = useState<ipc.ProcessedArea | undefined>()
|
const [hoveredProcessedArea, setHoveredProcessedArea] = useState<entities.ProcessedArea | undefined>()
|
||||||
|
|
||||||
const areas = getSelectedDocument()?.areas || []
|
const areas = getSelectedDocument()?.areas || []
|
||||||
const { width, height, zoomDetails, setZoomLevel } = props
|
const { width, height, zoomDetails, setZoomLevel } = props
|
||||||
|
|||||||
@ -1,28 +1,6 @@
|
|||||||
import isInBounds from '../../utils/isInBounds'
|
import isInBounds from '../../utils/isInBounds'
|
||||||
import { ipc } from '../../wailsjs/wailsjs/go/models'
|
import { entities } from '../../wailsjs/wailsjs/go/models'
|
||||||
|
import { AddAreaToStoreCallback, HoverOverAreaCallback, MouseCoordinates, RectangleCoordinates, SetZoomCallback, ZoomDetails } from './types'
|
||||||
|
|
||||||
type MouseCoordinates = {
|
|
||||||
startMouseX: number, startMouseY: number, endMouseX: number, endMouseY: number
|
|
||||||
}
|
|
||||||
|
|
||||||
type RectangleCoordinates = {
|
|
||||||
startX: number, startY: number, endX: number, endY: number
|
|
||||||
}
|
|
||||||
|
|
||||||
type AddAreaToStoreCallback =
|
|
||||||
(startX: number, startY: number, endX: number, endY: number)
|
|
||||||
=> Promise<void>
|
|
||||||
|
|
||||||
type SetZoomCallback = (newZoomLevel: number) => void
|
|
||||||
|
|
||||||
type ZoomDetails = {
|
|
||||||
currentZoomLevel: number,
|
|
||||||
maxZoomLevel: number,
|
|
||||||
zoomStep: number
|
|
||||||
}
|
|
||||||
|
|
||||||
type HoverOverAreaCallback = (areaId?: string) => void
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param uiCanvas
|
* @param uiCanvas
|
||||||
@ -75,7 +53,7 @@ const createUiCanvasInteractions = (uiCanvas: HTMLCanvasElement) => {
|
|||||||
if (shouldAttemptToZoomIn) setZoomCallBack(currentZoomLevel + zoomStep)
|
if (shouldAttemptToZoomIn) setZoomCallBack(currentZoomLevel + zoomStep)
|
||||||
else if (currentZoomLevel > (zoomStep * 2)) setZoomCallBack(currentZoomLevel - zoomStep)
|
else if (currentZoomLevel > (zoomStep * 2)) setZoomCallBack(currentZoomLevel - zoomStep)
|
||||||
},
|
},
|
||||||
onHoverOverArea: (mouseX: number, mouseY: number, zoomLevel: number, areas: ipc.Area[], callback: HoverOverAreaCallback) => {
|
onHoverOverArea: (mouseX: number, mouseY: number, zoomLevel: number, areas: entities.Area[], callback: HoverOverAreaCallback) => {
|
||||||
if (!areas.length) return
|
if (!areas.length) return
|
||||||
|
|
||||||
const domRect = uiCanvas.getBoundingClientRect()
|
const domRect = uiCanvas.getBoundingClientRect()
|
||||||
|
|||||||
19
frontend/components/DocumentCanvas/types.ts
Normal file
19
frontend/components/DocumentCanvas/types.ts
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
export type MouseCoordinates = {
|
||||||
|
startMouseX: number, startMouseY: number, endMouseX: number, endMouseY: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export type RectangleCoordinates = {
|
||||||
|
startX: number, startY: number, endX: number, endY: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export type AddAreaToStoreCallback = (startX: number, startY: number, endX: number, endY: number) => Promise<void>
|
||||||
|
|
||||||
|
export type SetZoomCallback = (newZoomLevel: number) => void
|
||||||
|
|
||||||
|
export type ZoomDetails = {
|
||||||
|
currentZoomLevel: number,
|
||||||
|
maxZoomLevel: number,
|
||||||
|
zoomStep: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export type HoverOverAreaCallback = (areaId?: string) => void
|
||||||
@ -7,7 +7,7 @@ import { useNavigation } from '../../context/Navigation/provider'
|
|||||||
import { mainPages } from '../../context/Navigation/types'
|
import { mainPages } from '../../context/Navigation/types'
|
||||||
import { useProject } from '../../context/Project/provider'
|
import { useProject } from '../../context/Project/provider'
|
||||||
import { GetAllLocalProjects } from '../../wailsjs/wailsjs/go/ipc/Channel'
|
import { GetAllLocalProjects } from '../../wailsjs/wailsjs/go/ipc/Channel'
|
||||||
import { ipc } from '../../wailsjs/wailsjs/go/models'
|
import { entities } from '../../wailsjs/wailsjs/go/models'
|
||||||
import NewProjectModal from './NewProjectModal'
|
import NewProjectModal from './NewProjectModal'
|
||||||
import ProjectListModal from './ProjectListModal'
|
import ProjectListModal from './ProjectListModal'
|
||||||
|
|
||||||
@ -17,7 +17,7 @@ const MainProject = () => {
|
|||||||
const [isProjectListModal, setIsProjectListModal] = useState(false)
|
const [isProjectListModal, setIsProjectListModal] = useState(false)
|
||||||
const [canPopoverBeOpen, setCanPopoverBeOpen] = useState(true)
|
const [canPopoverBeOpen, setCanPopoverBeOpen] = useState(true)
|
||||||
|
|
||||||
const [avalibleProjects, setAvalibleProjects] = useState<ipc.Project[]>([])
|
const [avalibleProjects, setAvalibleProjects] = useState<entities.Project[]>([])
|
||||||
const { createNewProject, requestSelectProjectByName } = useProject()
|
const { createNewProject, requestSelectProjectByName } = useProject()
|
||||||
const { setSelectedMainPage } = useNavigation()
|
const { setSelectedMainPage } = useNavigation()
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { ipc } from '../../wailsjs/wailsjs/go/models'
|
import { entities } from '../../wailsjs/wailsjs/go/models'
|
||||||
|
|
||||||
type Props = { projects: ipc.Project[], onSelectProjectHandler: (projectName: string) => void }
|
type Props = { projects: entities.Project[], onSelectProjectHandler: (projectName: string) => void }
|
||||||
const ProjectListModal = (props: Props) => {
|
const ProjectListModal = (props: Props) => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@ -5,17 +5,17 @@ import { useEffect, useState } from 'react'
|
|||||||
import { useProject } from '../../context/Project/provider'
|
import { useProject } from '../../context/Project/provider'
|
||||||
import classNames from '../../utils/classNames'
|
import classNames from '../../utils/classNames'
|
||||||
import getSupportedLanguages from '../../utils/getSupportedLanguages'
|
import getSupportedLanguages from '../../utils/getSupportedLanguages'
|
||||||
import { ipc } from '../../wailsjs/wailsjs/go/models'
|
import { entities } from '../../wailsjs/wailsjs/go/models'
|
||||||
|
|
||||||
type forAreaType = { shouldUpdateArea?: true, shouldUpdateDocument?: never }
|
type forAreaType = { shouldUpdateArea?: true, shouldUpdateDocument?: never }
|
||||||
type forDocumentType = { shouldUpdateDocument?: true, shouldUpdateArea?: never }
|
type forDocumentType = { shouldUpdateDocument?: true, shouldUpdateArea?: never }
|
||||||
type Props = (forAreaType | forDocumentType) & { defaultLanguage?: ipc.Language }
|
type Props = (forAreaType | forDocumentType) & { defaultLanguage?: entities.Language }
|
||||||
|
|
||||||
const LanguageSelect = (props?: Props) => {
|
const LanguageSelect = (props?: Props) => {
|
||||||
const { requestUpdateDocument, getSelectedDocument } = useProject()
|
const { requestUpdateDocument, getSelectedDocument } = useProject()
|
||||||
const [languages, setLanguages] = useState<ipc.Language[]>([])
|
const [languages, setLanguages] = useState<entities.Language[]>([])
|
||||||
const [query, setQuery] = useState('')
|
const [query, setQuery] = useState('')
|
||||||
const [selectedLanguage, setSelectedLanguage] = useState<ipc.Language | undefined>(props?.defaultLanguage)
|
const [selectedLanguage, setSelectedLanguage] = useState<entities.Language | undefined>(props?.defaultLanguage)
|
||||||
|
|
||||||
|
|
||||||
const filteredLanguages = query === ''
|
const filteredLanguages = query === ''
|
||||||
@ -47,7 +47,7 @@ const LanguageSelect = (props?: Props) => {
|
|||||||
style={{'maxWidth': '240px', 'height': '30px'}}
|
style={{'maxWidth': '240px', 'height': '30px'}}
|
||||||
className="rounded-md border border-gray-300 bg-white py-2 pl-3 pr-10 shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-1 focus:ring-indigo-500 sm:text-sm"
|
className="rounded-md border border-gray-300 bg-white py-2 pl-3 pr-10 shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-1 focus:ring-indigo-500 sm:text-sm"
|
||||||
onChange={(event) => setQuery(event.target.value)}
|
onChange={(event) => setQuery(event.target.value)}
|
||||||
displayValue={(language: ipc.Language) => language?.displayName}
|
displayValue={(language: entities.Language) => language?.displayName}
|
||||||
placeholder='Document Language'
|
placeholder='Document Language'
|
||||||
/>
|
/>
|
||||||
<Combobox.Button className="absolute inset-y-0 right-0 flex items-center rounded-r-md px-2 focus:outline-none">
|
<Combobox.Button className="absolute inset-y-0 right-0 flex items-center rounded-r-md px-2 focus:outline-none">
|
||||||
|
|||||||
@ -56,7 +56,7 @@ const DocumentLineItem = (props: { document: SidebarDocument, groupId: string, i
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<li className='p-0 m-0' key={props.document.id}>
|
<li className='p-0 m-0' key={props.document.id}>
|
||||||
{!props.document.areas.length
|
{!props.document.areas?.length
|
||||||
?
|
?
|
||||||
<div
|
<div
|
||||||
onClick={() => onDocumentClickHandler(props.document.id)}
|
onClick={() => onDocumentClickHandler(props.document.id)}
|
||||||
@ -149,52 +149,6 @@ const DocumentLineItem = (props: { document: SidebarDocument, groupId: string, i
|
|||||||
<ul>
|
<ul>
|
||||||
{props.document.areas.map((a, index) => (
|
{props.document.areas.map((a, index) => (
|
||||||
<AreaLineItem key={a.id} area={a} index={index} documentId={props.document.id} />
|
<AreaLineItem key={a.id} area={a} index={index} documentId={props.document.id} />
|
||||||
// <li key={a.id}>
|
|
||||||
// {selectedAreaId === a.id && isEditAreaNameInputShowing
|
|
||||||
// ? <input
|
|
||||||
// type="text"
|
|
||||||
// name="areaName"
|
|
||||||
// id="areaName"
|
|
||||||
// autoFocus
|
|
||||||
// className="h-8 text-white placeholder-gray-400 bg-gray-900 bg-opacity-5 block w-full rounded-none rounded-l-md border-late-700 focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm"
|
|
||||||
// placeholder={a.name || `Area ${index}`}
|
|
||||||
// onBlur={onAreaInputBlur}
|
|
||||||
// onKeyDown={(event) => {
|
|
||||||
// onEnterHandler(event,
|
|
||||||
// () => onConfirmAreaNameChangeHandler({ areaId: a.id, areaName: event.currentTarget.value }))
|
|
||||||
// }}
|
|
||||||
// ref={editAreaNameTextInput}
|
|
||||||
// />
|
|
||||||
// : <div
|
|
||||||
// draggable
|
|
||||||
// onDragOver={() => onAreaDragOver(a.id)}
|
|
||||||
// onDragStart={() => onAreaDragStart(a.id)}
|
|
||||||
// onDragEnd={() => onAreaDropEnd(a.id)}
|
|
||||||
// className={classNames('flex justify-between items-center cursor-pointer',
|
|
||||||
// selectedAreaId === a.id ? 'bg-indigo-500 text-gray-200' : 'text-gray-300 hover:bg-gray-700 hover:text-white',
|
|
||||||
// dragOverAreaId === a.id ? 'bg-gray-300 text-gray-700' : '',
|
|
||||||
// selectedAreaId === a.id && dragOverAreaId === a.id ? 'bg-indigo-300' : '',
|
|
||||||
// )}>
|
|
||||||
// <a
|
|
||||||
// role='button'
|
|
||||||
// onClick={() => onAreaClick(a.id)}
|
|
||||||
// onDoubleClick={() => onAreaDoubleClick(a.id)}
|
|
||||||
// className={classNames('group w-full pr-2 py-2 text-left font-medium pl-8 text-xs',
|
|
||||||
// 'rounded-md focus:outline-none focus:ring-2 focus:ring-indigo-500 py-2 select-none',
|
|
||||||
// )}>
|
|
||||||
// {a.name || `Area ${a.order}`}
|
|
||||||
// </a>
|
|
||||||
// <ArrowPathIcon
|
|
||||||
// className='w-6 h-5 mr-2 text-white hover:bg-white hover:text-gray-700 rounded-full p-0.5'
|
|
||||||
// aria-hidden="true"
|
|
||||||
// onClick={() => console.log('refresh')}
|
|
||||||
// />
|
|
||||||
// <XMarkIcon
|
|
||||||
// className='w-6 h-5 mr-2 text-white hover:bg-red-400 hover:text-gray-100 rounded-full p-0.5'
|
|
||||||
// onClick={() => handleAreaDeleteButtonClick(a.id)} />
|
|
||||||
// </div>
|
|
||||||
// }
|
|
||||||
// </li>
|
|
||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
</details>
|
</details>
|
||||||
|
|||||||
@ -1,17 +1,14 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { DocumentPlusIcon, PlusIcon, XMarkIcon } from '@heroicons/react/24/outline'
|
import { DocumentPlusIcon, PlusIcon, XMarkIcon } from '@heroicons/react/24/outline'
|
||||||
import React, { useRef, useState } from 'react'
|
import React, { useRef } from 'react'
|
||||||
import { useProject } from '../../../context/Project/provider'
|
import { useProject } from '../../../context/Project/provider'
|
||||||
import classNames from '../../../utils/classNames'
|
import classNames from '../../../utils/classNames'
|
||||||
import onEnterHandler from '../../../utils/onEnterHandler'
|
import onEnterHandler from '../../../utils/onEnterHandler'
|
||||||
import AddGroupInput from './AddGroupInput'
|
|
||||||
import DocumentLineItem from './DocumentLineItem'
|
import DocumentLineItem from './DocumentLineItem'
|
||||||
import { useSidebar } from './provider'
|
import { useSidebar } from './provider'
|
||||||
import { SidebarGroup } from './types'
|
import { SidebarGroup } from './types'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const GroupLineItem = (props: { group: SidebarGroup, dragOverGroupId?: string }) => {
|
const GroupLineItem = (props: { group: SidebarGroup, dragOverGroupId?: string }) => {
|
||||||
const {
|
const {
|
||||||
requestAddDocument,
|
requestAddDocument,
|
||||||
@ -58,10 +55,6 @@ const GroupLineItem = (props: { group: SidebarGroup, dragOverGroupId?: string })
|
|||||||
setDragOverGroupId(groupId)
|
setDragOverGroupId(groupId)
|
||||||
}
|
}
|
||||||
|
|
||||||
const onGroupDragStart = (groupId: string) => {
|
|
||||||
setSelectedGroupId(groupId)
|
|
||||||
}
|
|
||||||
|
|
||||||
const onGroupDropEnd = (groupId: string) => {
|
const onGroupDropEnd = (groupId: string) => {
|
||||||
if (!groupId || groupId == dragOverGroupId) return
|
if (!groupId || groupId == dragOverGroupId) return
|
||||||
|
|
||||||
@ -136,140 +129,6 @@ const GroupLineItem = (props: { group: SidebarGroup, dragOverGroupId?: string })
|
|||||||
<ul>
|
<ul>
|
||||||
{props.group.documents.map((d, index) => (
|
{props.group.documents.map((d, index) => (
|
||||||
<DocumentLineItem key={d.id} document={d} index={index} groupId={props.group.id} />
|
<DocumentLineItem key={d.id} document={d} index={index} groupId={props.group.id} />
|
||||||
// <li className='p-0 m-0' key={d.id}>
|
|
||||||
// {!d.areas.length
|
|
||||||
// ?
|
|
||||||
// <div
|
|
||||||
// onClick={() => onDocumentClickHandler(d.id)}
|
|
||||||
// onDoubleClick={() => onDocumentDoubleClickHandler(d.id)}
|
|
||||||
// className={classNames(
|
|
||||||
// d.id === selectedDocumentId
|
|
||||||
// ? 'bg-gray-900 text-white'
|
|
||||||
// : 'text-gray-300 hover:bg-gray-700 hover:text-white',
|
|
||||||
// 'group items-center py-2 text-base font-medium rounded-b-md pl-10',
|
|
||||||
// index !== 0 ? 'rounded-t-md' : '',
|
|
||||||
// )}>
|
|
||||||
// {selectedDocumentId === d.id && isEditDocumentNameInputShowing
|
|
||||||
// ? <input
|
|
||||||
// type="text"
|
|
||||||
// name="documentName"
|
|
||||||
// id="documentName"
|
|
||||||
// autoFocus
|
|
||||||
// className="h-8 w-[calc(100%-18px)] text-white placeholder-gray-400 bg-gray-900 bg-opacity-5 inline-block rounded-none rounded-l-md border-late-700 focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm"
|
|
||||||
// defaultValue={d.name}
|
|
||||||
// onBlur={onDocumentInputBlur}
|
|
||||||
// onKeyDown={(event) => {
|
|
||||||
// onEnterHandler(event,
|
|
||||||
// () => onConfirmDocumentNameChangeHandler(event.currentTarget.value))
|
|
||||||
// }}
|
|
||||||
// ref={editDocumentNameTextInput}
|
|
||||||
// />
|
|
||||||
// : <a
|
|
||||||
// role='button'
|
|
||||||
// className={classNames(
|
|
||||||
// d.id === selectedDocumentId
|
|
||||||
// ? 'bg-gray-900 text-white'
|
|
||||||
// : 'text-gray-300 hover:bg-gray-700 hover:text-white',
|
|
||||||
// 'text-left font-medium text-sm rounded-md focus:outline-none focus:ring-2 focus:ring-indigo-500 '
|
|
||||||
// )}
|
|
||||||
// >
|
|
||||||
// {d.name}
|
|
||||||
// </a>
|
|
||||||
// }
|
|
||||||
// </div>
|
|
||||||
// : <details>
|
|
||||||
// <summary
|
|
||||||
// onClick={() => onDocumentClickHandler(d.id)}
|
|
||||||
// onDoubleClick={() => onDocumentDoubleClickHandler(d.id)}
|
|
||||||
// className={classNames(
|
|
||||||
// d.id === selectedDocumentId
|
|
||||||
// ? 'bg-gray-900 text-white'
|
|
||||||
// : 'text-gray-300 hover:bg-gray-700 hover:text-white',
|
|
||||||
// 'group items-center py-2 text-base font-medium rounded-b-md pl-6',
|
|
||||||
// index !== 0 ? 'rounded-t-md' : '',
|
|
||||||
|
|
||||||
// )}>
|
|
||||||
// {selectedDocumentId === d.id && isEditDocumentNameInputShowing
|
|
||||||
// ? <input
|
|
||||||
// type="text"
|
|
||||||
// name="documentName"
|
|
||||||
// id="documentName"
|
|
||||||
// autoFocus
|
|
||||||
// className="h-8 w-[calc(100%-18px)] text-white placeholder-gray-400 bg-gray-900 bg-opacity-5 inline-block rounded-none rounded-l-md border-late-700 focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm"
|
|
||||||
// defaultValue={d.name}
|
|
||||||
// onBlur={onDocumentInputBlur}
|
|
||||||
// onKeyDown={(event) => {
|
|
||||||
// onEnterHandler(event,
|
|
||||||
// () => onConfirmDocumentNameChangeHandler(event.currentTarget.value))
|
|
||||||
// }}
|
|
||||||
// ref={editDocumentNameTextInput}
|
|
||||||
// />
|
|
||||||
// : <a
|
|
||||||
// role='button'
|
|
||||||
// className={classNames(
|
|
||||||
// d.id === selectedDocumentId
|
|
||||||
// ? 'bg-gray-900 text-white'
|
|
||||||
// : 'text-gray-300 hover:bg-gray-700 hover:text-white',
|
|
||||||
// 'text-left font-medium text-sm rounded-md focus:outline-none focus:ring-2 focus:ring-indigo-500 '
|
|
||||||
// )}
|
|
||||||
// >
|
|
||||||
// {d.name}
|
|
||||||
// </a>
|
|
||||||
// }
|
|
||||||
// </summary>
|
|
||||||
// <ul>
|
|
||||||
// {d.areas.map((a, index) => (
|
|
||||||
// <li key={a.id}>
|
|
||||||
// {selectedAreaId === a.id && isEditAreaNameInputShowing
|
|
||||||
// ? <input
|
|
||||||
// type="text"
|
|
||||||
// name="areaName"
|
|
||||||
// id="areaName"
|
|
||||||
// autoFocus
|
|
||||||
// className="h-8 text-white placeholder-gray-400 bg-gray-900 bg-opacity-5 block w-full rounded-none rounded-l-md border-late-700 focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm"
|
|
||||||
// placeholder={a.name || `Area ${index}`}
|
|
||||||
// onBlur={onAreaInputBlur}
|
|
||||||
// onKeyDown={(event) => {
|
|
||||||
// onEnterHandler(event,
|
|
||||||
// () => onConfirmAreaNameChangeHandler({ areaId: a.id, areaName: event.currentTarget.value }))
|
|
||||||
// }}
|
|
||||||
// ref={editAreaNameTextInput}
|
|
||||||
// />
|
|
||||||
// : <div
|
|
||||||
// draggable
|
|
||||||
// onDragOver={() => onAreaDragOver(a.id)}
|
|
||||||
// onDragStart={() => onAreaDragStart(a.id)}
|
|
||||||
// onDragEnd={() => onAreaDropEnd(a.id)}
|
|
||||||
// className={classNames('flex justify-between items-center cursor-pointer',
|
|
||||||
// selectedAreaId === a.id ? 'bg-indigo-500 text-gray-200' : 'text-gray-300 hover:bg-gray-700 hover:text-white',
|
|
||||||
// dragOverAreaId === a.id ? 'bg-gray-300 text-gray-700' : '',
|
|
||||||
// selectedAreaId === a.id && dragOverAreaId === a.id ? 'bg-indigo-300' : '',
|
|
||||||
// )}>
|
|
||||||
// <a
|
|
||||||
// role='button'
|
|
||||||
// onClick={() => onAreaClick(a.id)}
|
|
||||||
// onDoubleClick={() => onAreaDoubleClick(a.id)}
|
|
||||||
// className={classNames('group w-full pr-2 py-2 text-left font-medium pl-8 text-xs',
|
|
||||||
// 'rounded-md focus:outline-none focus:ring-2 focus:ring-indigo-500 py-2 select-none',
|
|
||||||
// )}>
|
|
||||||
// {a.name || `Area ${a.order}`}
|
|
||||||
// </a>
|
|
||||||
// <ArrowPathIcon
|
|
||||||
// className='w-6 h-5 mr-2 text-white hover:bg-white hover:text-gray-700 rounded-full p-0.5'
|
|
||||||
// aria-hidden="true"
|
|
||||||
// onClick={() => console.log('refresh')}
|
|
||||||
// />
|
|
||||||
// <XMarkIcon
|
|
||||||
// className='w-6 h-5 mr-2 text-white hover:bg-red-400 hover:text-gray-100 rounded-full p-0.5'
|
|
||||||
// onClick={() => handleAreaDeleteButtonClick(a.id)} />
|
|
||||||
// </div>
|
|
||||||
// }
|
|
||||||
// </li>
|
|
||||||
// ))}
|
|
||||||
// </ul>
|
|
||||||
// </details>
|
|
||||||
// }
|
|
||||||
// </li>
|
|
||||||
))}
|
))}
|
||||||
|
|
||||||
{renderAddNewDocument(props.group.id)}
|
{renderAddNewDocument(props.group.id)}
|
||||||
|
|||||||
@ -16,6 +16,10 @@ const makeDefaultSidebar = (): SidebarContextType => ({
|
|||||||
setIsAddNewGroupInputShowing: (_: boolean) => {},
|
setIsAddNewGroupInputShowing: (_: boolean) => {},
|
||||||
isEditAreaNameInputShowing: false,
|
isEditAreaNameInputShowing: false,
|
||||||
setIsEditAreaNameInputShowing: (_: boolean) => {},
|
setIsEditAreaNameInputShowing: (_: boolean) => {},
|
||||||
|
dragOverGroupId: '',
|
||||||
|
setDragOverGroupId: (_: string) => {},
|
||||||
|
dragOverAreaId: '',
|
||||||
|
setDragOverAreaId: (_: string) => {},
|
||||||
})
|
})
|
||||||
|
|
||||||
export default makeDefaultSidebar
|
export default makeDefaultSidebar
|
||||||
@ -1,14 +1,14 @@
|
|||||||
import { ipc } from '../../../wailsjs/wailsjs/go/models'
|
import { entities } from '../../../wailsjs/wailsjs/go/models'
|
||||||
import { SidebarGroup } from './types'
|
import { SidebarGroup } from './types'
|
||||||
|
|
||||||
const getNavigationProps = (documents: ipc.Document[], groups: ipc.Group[]) : SidebarGroup[] => {
|
const getNavigationProps = (documents: entities.Document[], groups: entities.Group[]) : SidebarGroup[] => {
|
||||||
const groupsWithDocuments = groups.map(g => {
|
const groupsWithDocuments = groups.map(g => {
|
||||||
const childrenDocuments = documents
|
const childrenDocuments = documents
|
||||||
.filter(d => d.groupId === g.id)
|
.filter(d => d.groupId === g.id)
|
||||||
.map(d => ({
|
.map(d => ({
|
||||||
id: d.id,
|
id: d.id,
|
||||||
name: d.name,
|
name: d.name,
|
||||||
areas: d.areas.map(a => ({ id: a.id, name: a.name, order: a.order }))//.sort((a, b) => a.order - b.order)
|
areas: d.areas?.map(a => ({ id: a.id, name: a.name, order: a.order }))//.sort((a, b) => a.order - b.order)
|
||||||
}))
|
}))
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -23,7 +23,7 @@ const getNavigationProps = (documents: ipc.Document[], groups: ipc.Group[]) : Si
|
|||||||
.map(d => ({
|
.map(d => ({
|
||||||
id: d.id,
|
id: d.id,
|
||||||
name: d.name,
|
name: d.name,
|
||||||
areas: d.areas.map(a => ({ id: a.id, name: a.name, order: a.order }))//.sort((a, b) => a.order - b.order)
|
areas: d.areas?.map(a => ({ id: a.id, name: a.name, order: a.order }))//.sort((a, b) => a.order - b.order)
|
||||||
}))
|
}))
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
|||||||
@ -1,10 +1,10 @@
|
|||||||
import { saveDocuments } from '../../useCases/saveData'
|
import { saveDocuments } from '../../useCases/saveData'
|
||||||
import { GetProcessedAreasByDocumentId, RequestAddArea, RequestAddProcessedArea, RequestChangeAreaOrder, RequestDeleteAreaById, RequestUpdateArea } from '../../wailsjs/wailsjs/go/ipc/Channel'
|
import { GetProcessedAreasByDocumentId, RequestAddArea, RequestAddProcessedArea, RequestChangeAreaOrder, RequestDeleteAreaById, RequestUpdateArea } from '../../wailsjs/wailsjs/go/ipc/Channel'
|
||||||
import { ipc } from '../../wailsjs/wailsjs/go/models'
|
import { entities, ipc } from '../../wailsjs/wailsjs/go/models'
|
||||||
import { AddAreaProps, AreaProps } from './types'
|
import { AddAreaProps, AreaProps } from './types'
|
||||||
|
|
||||||
type Dependencies = {
|
type Dependencies = {
|
||||||
documents: ipc.Document[]
|
documents: entities.Document[]
|
||||||
updateDocuments: () => Promise<ipc.GetDocumentsResponse>
|
updateDocuments: () => Promise<ipc.GetDocumentsResponse>
|
||||||
selectedDocumentId: string
|
selectedDocumentId: string
|
||||||
}
|
}
|
||||||
@ -12,7 +12,7 @@ type Dependencies = {
|
|||||||
const createAreaProviderMethods = (dependencies: Dependencies) => {
|
const createAreaProviderMethods = (dependencies: Dependencies) => {
|
||||||
const { documents, updateDocuments, selectedDocumentId } = dependencies
|
const { documents, updateDocuments, selectedDocumentId } = dependencies
|
||||||
|
|
||||||
const getAreaById = (areaId: string): ipc.Area | undefined => (
|
const getAreaById = (areaId: string): entities.Area | undefined => (
|
||||||
documents.map(d => d.areas).flat().find(a => a.id === areaId)
|
documents.map(d => d.areas).flat().find(a => a.id === areaId)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ const createAreaProviderMethods = (dependencies: Dependencies) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const getProcessedAreasByDocumentId = async (documentId: string) => {
|
const getProcessedAreasByDocumentId = async (documentId: string) => {
|
||||||
let response: ipc.ProcessedArea[] = []
|
let response: entities.ProcessedArea[] = []
|
||||||
try {
|
try {
|
||||||
response = await GetProcessedAreasByDocumentId(documentId)
|
response = await GetProcessedAreasByDocumentId(documentId)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@ -38,15 +38,15 @@ const createAreaProviderMethods = (dependencies: Dependencies) => {
|
|||||||
return response
|
return response
|
||||||
}
|
}
|
||||||
|
|
||||||
const requestAddArea = async (documentId: string, area: AddAreaProps): Promise<ipc.Area> => {
|
const requestAddArea = async (documentId: string, area: AddAreaProps): Promise<entities.Area> => {
|
||||||
const response = await RequestAddArea(documentId, new ipc.Area(area))
|
const response = await RequestAddArea(documentId, new entities.Area(area))
|
||||||
if (response.id) await updateDocuments()
|
if (response.id) await updateDocuments()
|
||||||
saveDocuments()
|
saveDocuments()
|
||||||
return response
|
return response
|
||||||
}
|
}
|
||||||
|
|
||||||
const requestUpdateArea = async (updatedArea: AreaProps): Promise<ipc.Area> => {
|
const requestUpdateArea = async (updatedArea: AreaProps): Promise<entities.Area> => {
|
||||||
const response = await RequestUpdateArea(new ipc.Area(updatedArea))
|
const response = await RequestUpdateArea(new entities.Area(updatedArea))
|
||||||
|
|
||||||
if (response.id) await updateDocuments()
|
if (response.id) await updateDocuments()
|
||||||
saveDocuments()
|
saveDocuments()
|
||||||
@ -60,7 +60,7 @@ const createAreaProviderMethods = (dependencies: Dependencies) => {
|
|||||||
return wasSuccessfulDeletion
|
return wasSuccessfulDeletion
|
||||||
}
|
}
|
||||||
|
|
||||||
const requestAddProcessedArea = async (processedArea: ipc.ProcessedArea) => await RequestAddProcessedArea(processedArea)
|
const requestAddProcessedArea = async (processedArea: entities.ProcessedArea) => await RequestAddProcessedArea(processedArea)
|
||||||
|
|
||||||
const requestChangeAreaOrder = async (areaId: string, newOrder: number) => {
|
const requestChangeAreaOrder = async (areaId: string, newOrder: number) => {
|
||||||
const response = await RequestChangeAreaOrder(areaId, newOrder)
|
const response = await RequestChangeAreaOrder(areaId, newOrder)
|
||||||
|
|||||||
@ -1,20 +1,20 @@
|
|||||||
import { saveGroups } from '../../useCases/saveData'
|
import { saveGroups } from '../../useCases/saveData'
|
||||||
import { RequestAddDocument, RequestAddDocumentGroup, RequestChangeGroupOrder, RequestDeleteDocumentAndChildren, RequestUpdateDocument, RequestUpdateProcessedWordById } from '../../wailsjs/wailsjs/go/ipc/Channel'
|
import { RequestAddDocument, RequestAddDocumentGroup, RequestChangeGroupOrder, RequestDeleteDocumentAndChildren, RequestUpdateDocument, RequestUpdateProcessedWordById } from '../../wailsjs/wailsjs/go/ipc/Channel'
|
||||||
import { ipc } from '../../wailsjs/wailsjs/go/models'
|
import { ipc, entities } from '../../wailsjs/wailsjs/go/models'
|
||||||
import { UpdateDocumentRequest } from './types'
|
import { UpdateDocumentRequest } from './types'
|
||||||
|
|
||||||
type Dependencies = {
|
type Dependencies = {
|
||||||
selectedDocumentId: string
|
selectedDocumentId: string
|
||||||
documents: ipc.Document[]
|
documents: entities.Document[]
|
||||||
saveDocuments: () => Promise<void>
|
saveDocuments: () => Promise<void>
|
||||||
updateDocuments: () => Promise<ipc.GetDocumentsResponse>
|
updateDocuments: () => Promise<ipc.GetDocumentsResponse>
|
||||||
groups: ipc.Group[]
|
groups: entities.Group[]
|
||||||
}
|
}
|
||||||
|
|
||||||
const createDocumentProviderMethods = (dependencies: Dependencies) => {
|
const createDocumentProviderMethods = (dependencies: Dependencies) => {
|
||||||
const { selectedDocumentId, documents, saveDocuments, updateDocuments, groups } = dependencies
|
const { selectedDocumentId, documents, saveDocuments, updateDocuments, groups } = dependencies
|
||||||
|
|
||||||
const getGroupById = (groupId: string): ipc.Group | undefined => (
|
const getGroupById = (groupId: string): entities.Group | undefined => (
|
||||||
groups.find(g => g.id === groupId)
|
groups.find(g => g.id === groupId)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ const createDocumentProviderMethods = (dependencies: Dependencies) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const requestUpdateDocument = async (documentProps: UpdateDocumentRequest) => {
|
const requestUpdateDocument = async (documentProps: UpdateDocumentRequest) => {
|
||||||
const response = await RequestUpdateDocument(new ipc.Document(documentProps))
|
const response = await RequestUpdateDocument(new entities.Document(documentProps))
|
||||||
await updateDocuments()
|
await updateDocuments()
|
||||||
saveDocuments()
|
saveDocuments()
|
||||||
return response
|
return response
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
import { CreateNewProject, RequestChangeSessionProjectByName, RequestChooseUserAvatar, RequestUpdateCurrentUser } from '../../wailsjs/wailsjs/go/ipc/Channel'
|
import { CreateNewProject, RequestChangeSessionProjectByName, RequestChooseUserAvatar, RequestUpdateCurrentUser } from '../../wailsjs/wailsjs/go/ipc/Channel'
|
||||||
import { ipc } from '../../wailsjs/wailsjs/go/models'
|
import { ipc, entities } from '../../wailsjs/wailsjs/go/models'
|
||||||
import { UserProps } from './types'
|
import { UserProps } from './types'
|
||||||
|
|
||||||
type Dependencies = {
|
type Dependencies = {
|
||||||
updateSession: () => Promise<ipc.Session>
|
updateSession: () => Promise<entities.Session>
|
||||||
updateDocuments: () => Promise<ipc.GetDocumentsResponse>
|
updateDocuments: () => Promise<ipc.GetDocumentsResponse>
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -17,7 +17,7 @@ const createSessionProviderMethods = (dependencies: Dependencies) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const requestUpdateCurrentUser = async (userProps: UserProps) => {
|
const requestUpdateCurrentUser = async (userProps: UserProps) => {
|
||||||
const response = await RequestUpdateCurrentUser(new ipc.User(userProps))
|
const response = await RequestUpdateCurrentUser(new entities.User(userProps))
|
||||||
await updateSession()
|
await updateSession()
|
||||||
return response
|
return response
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,13 +1,13 @@
|
|||||||
import { saveUserProcessedMarkdown } from '../../useCases/saveData'
|
import { saveUserProcessedMarkdown } from '../../useCases/saveData'
|
||||||
import { GetUserMarkdownByDocumentId, RequestUpdateDocumentUserMarkdown } from '../../wailsjs/wailsjs/go/ipc/Channel'
|
import { GetUserMarkdownByDocumentId, RequestUpdateDocumentUserMarkdown } from '../../wailsjs/wailsjs/go/ipc/Channel'
|
||||||
import { ipc } from '../../wailsjs/wailsjs/go/models'
|
import { ipc, entities } from '../../wailsjs/wailsjs/go/models'
|
||||||
|
|
||||||
type Dependencies = {}
|
type Dependencies = {}
|
||||||
|
|
||||||
const createUserMarkdownProviderMethods = (dependencies?: Dependencies) => {
|
const createUserMarkdownProviderMethods = (dependencies?: Dependencies) => {
|
||||||
|
|
||||||
const requestUpdateDocumentUserMarkdown = async (documentId: string, markdown: string) => {
|
const requestUpdateDocumentUserMarkdown = async (documentId: string, markdown: string) => {
|
||||||
let response: ipc.UserMarkdown = new ipc.UserMarkdown()
|
let response = new entities.UserMarkdown()
|
||||||
try {
|
try {
|
||||||
response = await RequestUpdateDocumentUserMarkdown(documentId, markdown)
|
response = await RequestUpdateDocumentUserMarkdown(documentId, markdown)
|
||||||
await saveUserProcessedMarkdown()
|
await saveUserProcessedMarkdown()
|
||||||
@ -17,8 +17,8 @@ const createUserMarkdownProviderMethods = (dependencies?: Dependencies) => {
|
|||||||
return response
|
return response
|
||||||
}
|
}
|
||||||
|
|
||||||
const getUserMarkdownByDocumentId = async (documentId: string): Promise<ipc.UserMarkdown> => {
|
const getUserMarkdownByDocumentId = async (documentId: string): Promise<entities.UserMarkdown> => {
|
||||||
let response: ipc.UserMarkdown = new ipc.UserMarkdown({})
|
let response = new entities.UserMarkdown({})
|
||||||
try {
|
try {
|
||||||
response = await GetUserMarkdownByDocumentId(documentId)
|
response = await GetUserMarkdownByDocumentId(documentId)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
@ -1,33 +1,33 @@
|
|||||||
import { ipc } from '../../wailsjs/wailsjs/go/models'
|
import { entities } from '../../wailsjs/wailsjs/go/models'
|
||||||
import { ProjectContextType, UserProps } from './types'
|
import { ProjectContextType, UserProps } from './types'
|
||||||
|
|
||||||
const makeDefaultProject = (): ProjectContextType => ({
|
const makeDefaultProject = (): ProjectContextType => ({
|
||||||
id: '',
|
id: '',
|
||||||
documents: [] as ipc.Document[],
|
documents: [] as entities.Document[],
|
||||||
groups: [] as ipc.Group[],
|
groups: [] as entities.Group[],
|
||||||
selectedAreaId: '',
|
selectedAreaId: '',
|
||||||
selectedDocumentId: '',
|
selectedDocumentId: '',
|
||||||
getSelectedDocument: () => new ipc.Document(),
|
getSelectedDocument: () => new entities.Document(),
|
||||||
getAreaById: (areaId) => undefined,
|
getAreaById: (areaId) => undefined,
|
||||||
getProcessedAreasByDocumentId: (documentId) => Promise.resolve([new ipc.ProcessedArea()]),
|
getProcessedAreasByDocumentId: (documentId) => Promise.resolve([new entities.ProcessedArea()]),
|
||||||
requestAddProcessedArea: (processesArea) => Promise.resolve(new ipc.ProcessedArea()),
|
requestAddProcessedArea: (processesArea) => Promise.resolve(new entities.ProcessedArea()),
|
||||||
requestAddArea: (documentId, area) => Promise.resolve(new ipc.Area()),
|
requestAddArea: (documentId, area) => Promise.resolve(new entities.Area()),
|
||||||
requestUpdateArea: (updatedArea) => Promise.resolve(new ipc.Area()),
|
requestUpdateArea: (updatedArea) => Promise.resolve(new entities.Area()),
|
||||||
requestDeleteAreaById: (areaId) => Promise.resolve(false),
|
requestDeleteAreaById: (areaId) => Promise.resolve(false),
|
||||||
requestAddDocument: (groupId, documentName) => Promise.resolve(new ipc.Document()),
|
requestAddDocument: (groupId, documentName) => Promise.resolve(new entities.Document()),
|
||||||
requestDeleteDocumentById: (documentId) => Promise.resolve(false),
|
requestDeleteDocumentById: (documentId) => Promise.resolve(false),
|
||||||
requestAddDocumentGroup: (groupName: string) => Promise.resolve(new ipc.Group()),
|
requestAddDocumentGroup: (groupName: string) => Promise.resolve(new entities.Group()),
|
||||||
requestUpdateDocumentUserMarkdown: (documentId: string, markdown: string) => Promise.resolve(new ipc.UserMarkdown()),
|
requestUpdateDocumentUserMarkdown: (documentId: string, markdown: string) => Promise.resolve(new entities.UserMarkdown()),
|
||||||
getUserMarkdownByDocumentId: (documentId) => Promise.resolve(new ipc.UserMarkdown),
|
getUserMarkdownByDocumentId: (documentId) => Promise.resolve(new entities.UserMarkdown),
|
||||||
setSelectedAreaId: (id) => {},
|
setSelectedAreaId: (id) => {},
|
||||||
setSelectedDocumentId: (id) => {},
|
setSelectedDocumentId: (id) => {},
|
||||||
currentSession: new ipc.Session(),
|
currentSession: new entities.Session(),
|
||||||
createNewProject: (name: string) => Promise.resolve(new ipc.Session()),
|
createNewProject: (name: string) => Promise.resolve(new entities.Session()),
|
||||||
requestUpdateCurrentUser: (updatedUserProps: UserProps) => Promise.resolve(new ipc.User()),
|
requestUpdateCurrentUser: (updatedUserProps: UserProps) => Promise.resolve(new entities.User()),
|
||||||
requestChooseUserAvatar: () => Promise.resolve(''),
|
requestChooseUserAvatar: () => Promise.resolve(''),
|
||||||
requestUpdateDocument: ({}) => Promise.resolve(new ipc.Document),
|
requestUpdateDocument: ({}) => Promise.resolve(new entities.Document),
|
||||||
requestChangeAreaOrder: (areaId: string, newOrder: number) => Promise.resolve(new ipc.Document()),
|
requestChangeAreaOrder: (areaId: string, newOrder: number) => Promise.resolve(new entities.Document()),
|
||||||
requestChangeGroupOrder: (groupId: string, newOrder: number) => Promise.resolve(new ipc.Group()),
|
requestChangeGroupOrder: (groupId: string, newOrder: number) => Promise.resolve(new entities.Group()),
|
||||||
getGroupById: (groupId) => undefined,
|
getGroupById: (groupId) => undefined,
|
||||||
requestSelectProjectByName: (projectName) => Promise.resolve(false),
|
requestSelectProjectByName: (projectName) => Promise.resolve(false),
|
||||||
requestUpdateProcessedWordById: (wordId, newTestValue) => Promise.resolve(false),
|
requestUpdateProcessedWordById: (wordId, newTestValue) => Promise.resolve(false),
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import { createContext, ReactNode, useContext, useEffect, useState } from 'react'
|
import { createContext, ReactNode, useContext, useEffect, useState } from 'react'
|
||||||
import { GetCurrentSession, GetDocuments, } from '../../wailsjs/wailsjs/go/ipc/Channel'
|
import { GetCurrentSession, GetDocuments, } from '../../wailsjs/wailsjs/go/ipc/Channel'
|
||||||
import { ipc } from '../../wailsjs/wailsjs/go/models'
|
import { entities } from '../../wailsjs/wailsjs/go/models'
|
||||||
import { ProjectContextType, ProjectProps } from './types'
|
import { ProjectContextType, ProjectProps } from './types'
|
||||||
import makeDefaultProject from './makeDefaultProject'
|
import makeDefaultProject from './makeDefaultProject'
|
||||||
import { saveDocuments } from '../../useCases/saveData'
|
import { saveDocuments } from '../../useCases/saveData'
|
||||||
@ -19,11 +19,11 @@ export function useProject() {
|
|||||||
|
|
||||||
type Props = { children: ReactNode, projectProps: ProjectProps }
|
type Props = { children: ReactNode, projectProps: ProjectProps }
|
||||||
export function ProjectProvider({ children, projectProps }: Props) {
|
export function ProjectProvider({ children, projectProps }: Props) {
|
||||||
const [documents, setDocuments] = useState<ipc.Document[]>(projectProps.documents)
|
const [documents, setDocuments] = useState<entities.Document[]>(projectProps.documents)
|
||||||
const [groups, setGroups] = useState<ipc.Group[]>(projectProps.groups)
|
const [groups, setGroups] = useState<entities.Group[]>(projectProps.groups)
|
||||||
const [selectedAreaId, setSelectedAreaId] = useState<string>('')
|
const [selectedAreaId, setSelectedAreaId] = useState<string>('')
|
||||||
const [selectedDocumentId, setSelectedDocumentId] = useState<string>('')
|
const [selectedDocumentId, setSelectedDocumentId] = useState<string>('')
|
||||||
const [currentSession, setCurrentSession] = useState<ipc.Session>(new ipc.Session())
|
const [currentSession, setCurrentSession] = useState<entities.Session>(new entities.Session())
|
||||||
|
|
||||||
const updateDocuments = async () => {
|
const updateDocuments = async () => {
|
||||||
const response = await GetDocuments()
|
const response = await GetDocuments()
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
import { ipc } from '../../wailsjs/wailsjs/go/models'
|
import { ipc, entities } from '../../wailsjs/wailsjs/go/models'
|
||||||
|
|
||||||
export type ProjectProps = {
|
export type ProjectProps = {
|
||||||
id: string,
|
id: string,
|
||||||
documents: ipc.Document[],
|
documents: entities.Document[],
|
||||||
groups: ipc.Group[],
|
groups: entities.Group[],
|
||||||
}
|
}
|
||||||
|
|
||||||
export type AddAreaProps = {
|
export type AddAreaProps = {
|
||||||
@ -32,36 +32,36 @@ export type UpdateDocumentRequest = {
|
|||||||
groupId?: string,
|
groupId?: string,
|
||||||
name?: string,
|
name?: string,
|
||||||
path?: string,
|
path?: string,
|
||||||
areas?: ipc.Area[]
|
areas?: entities.Area[]
|
||||||
defaultLanguage?: ipc.Language
|
defaultLanguage?: entities.Language
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ProjectContextType = {
|
export type ProjectContextType = {
|
||||||
getSelectedDocument: () => ipc.Document | undefined
|
getSelectedDocument: () => entities.Document | undefined
|
||||||
getAreaById: (areaId: string) => ipc.Area | undefined
|
getAreaById: (areaId: string) => entities.Area | undefined
|
||||||
getProcessedAreasByDocumentId: (documentId: string) => Promise<ipc.ProcessedArea[]>
|
getProcessedAreasByDocumentId: (documentId: string) => Promise<entities.ProcessedArea[]>
|
||||||
requestAddProcessedArea: (processedArea: ipc.ProcessedArea) => Promise<ipc.ProcessedArea>
|
requestAddProcessedArea: (processedArea: entities.ProcessedArea) => Promise<entities.ProcessedArea>
|
||||||
requestAddArea: (documentId: string, area: AddAreaProps) => Promise<ipc.Area>
|
requestAddArea: (documentId: string, area: AddAreaProps) => Promise<entities.Area>
|
||||||
requestUpdateArea: (area: AreaProps) => Promise<ipc.Area>
|
requestUpdateArea: (area: AreaProps) => Promise<entities.Area>
|
||||||
requestDeleteAreaById: (areaId: string) => Promise<boolean>
|
requestDeleteAreaById: (areaId: string) => Promise<boolean>
|
||||||
requestAddDocument: (groupId: string, documentName: string) => Promise<ipc.Document>
|
requestAddDocument: (groupId: string, documentName: string) => Promise<entities.Document>
|
||||||
requestDeleteDocumentById: (documentId: string) => Promise<boolean>
|
requestDeleteDocumentById: (documentId: string) => Promise<boolean>
|
||||||
requestAddDocumentGroup: (groupName: string) => Promise<ipc.Group>
|
requestAddDocumentGroup: (groupName: string) => Promise<entities.Group>
|
||||||
requestUpdateDocumentUserMarkdown: (documentId: string, markdown: string) => Promise<ipc.UserMarkdown>
|
requestUpdateDocumentUserMarkdown: (documentId: string, markdown: string) => Promise<entities.UserMarkdown>
|
||||||
getUserMarkdownByDocumentId: (documentId: string) => Promise<ipc.UserMarkdown>
|
getUserMarkdownByDocumentId: (documentId: string) => Promise<entities.UserMarkdown>
|
||||||
selectedAreaId: string
|
selectedAreaId: string
|
||||||
setSelectedAreaId: (id: string) => void
|
setSelectedAreaId: (id: string) => void
|
||||||
selectedDocumentId: string
|
selectedDocumentId: string
|
||||||
setSelectedDocumentId: (id: string) => void
|
setSelectedDocumentId: (id: string) => void
|
||||||
currentSession: ipc.Session
|
currentSession: entities.Session
|
||||||
createNewProject: (name: string) => Promise<ipc.Session>
|
createNewProject: (name: string) => Promise<entities.Session>
|
||||||
requestUpdateCurrentUser: (updatedUserProps: UserProps) => Promise<ipc.User>
|
requestUpdateCurrentUser: (updatedUserProps: UserProps) => Promise<entities.User>
|
||||||
requestChooseUserAvatar: () => Promise<string>
|
requestChooseUserAvatar: () => Promise<string>
|
||||||
requestUpdateDocument: (request: UpdateDocumentRequest) => Promise<ipc.Document>
|
requestUpdateDocument: (request: UpdateDocumentRequest) => Promise<entities.Document>
|
||||||
requestChangeAreaOrder: (areaId: string, newOrder: number) => Promise<ipc.Document>
|
requestChangeAreaOrder: (areaId: string, newOrder: number) => Promise<entities.Document>
|
||||||
requestChangeGroupOrder: (groupId: string, newOrder: number) => Promise<ipc.Group>
|
requestChangeGroupOrder: (groupId: string, newOrder: number) => Promise<entities.Group>
|
||||||
getGroupById: (groupId: string) => ipc.Group | undefined
|
getGroupById: (groupId: string) => entities.Group | undefined
|
||||||
requestSelectProjectByName: (projectName: string) => Promise<boolean>
|
requestSelectProjectByName: (projectName: string) => Promise<boolean>
|
||||||
requestUpdateProcessedWordById: (wordId: string, newTextValue: string) => Promise<boolean>
|
requestUpdateProcessedWordById: (wordId: string, newTextValue: string) => Promise<boolean>
|
||||||
getProcessedAreaById: (areaId: string) => Promise<ipc.ProcessedArea | undefined>
|
getProcessedAreaById: (areaId: string) => Promise<entities.ProcessedArea | undefined>
|
||||||
} & ProjectProps
|
} & ProjectProps
|
||||||
@ -1,6 +1,6 @@
|
|||||||
import { createScheduler, createWorker } from 'tesseract.js'
|
import { createScheduler, createWorker } from 'tesseract.js'
|
||||||
import { GetAreaById, GetDocumentById, RequestAddProcessedArea, RequestSaveProcessedTextCollection } from '../wailsjs/wailsjs/go/ipc/Channel'
|
import { GetAreaById, GetDocumentById, RequestAddProcessedArea, RequestSaveProcessedTextCollection } from '../wailsjs/wailsjs/go/ipc/Channel'
|
||||||
import { ipc } from '../wailsjs/wailsjs/go/models'
|
import { entities } from '../wailsjs/wailsjs/go/models'
|
||||||
import loadImage from './loadImage'
|
import loadImage from './loadImage'
|
||||||
import { saveProcessedText } from './saveData'
|
import { saveProcessedText } from './saveData'
|
||||||
|
|
||||||
@ -31,27 +31,27 @@ const processImageArea = async (documentId: string, areaId: string) => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const addProcessesAreaRequest = await RequestAddProcessedArea(new ipc.ProcessedArea({
|
const addProcessesAreaRequest = await RequestAddProcessedArea(new entities.ProcessedArea({
|
||||||
id: foundArea.id,
|
id: foundArea.id,
|
||||||
documentId,
|
documentId,
|
||||||
order: foundArea.order,
|
order: foundArea.order,
|
||||||
fullText: result.data.text,
|
fullText: result.data.text,
|
||||||
lines: result.data.lines.map((l: any) => new ipc.ProcessedLine({
|
lines: result.data.lines.map((l: any) => new entities.ProcessedLine({
|
||||||
fullText: l.text,
|
fullText: l.text,
|
||||||
words: l.words.map((w: any) => new ipc.ProcessedWord({
|
words: l.words.map((w: any) => new entities.ProcessedWord({
|
||||||
fullText: w.text,
|
fullText: w.text,
|
||||||
direction: w.direction,
|
direction: w.direction,
|
||||||
confidence: w.confidence,
|
confidence: w.confidence,
|
||||||
boundingBox: new ipc.ProcessedBoundingBox({
|
boundingBox: new entities.ProcessedBoundingBox({
|
||||||
x0: w.bbox.x0,
|
x0: w.bbox.x0,
|
||||||
y0: w.bbox.y0,
|
y0: w.bbox.y0,
|
||||||
x1: w.bbox.x1,
|
x1: w.bbox.x1,
|
||||||
y1: w.bbox.y1,
|
y1: w.bbox.y1,
|
||||||
}),
|
}),
|
||||||
symbols: w.symbols.map((s: any) => new ipc.ProcessedSymbol({
|
symbols: w.symbols.map((s: any) => new entities.ProcessedSymbol({
|
||||||
fullText: s.text,
|
fullText: s.text,
|
||||||
confidence: s.confidence,
|
confidence: s.confidence,
|
||||||
boundingBox: new ipc.ProcessedBoundingBox({
|
boundingBox: new entities.ProcessedBoundingBox({
|
||||||
x0: s.bbox.x0,
|
x0: s.bbox.x0,
|
||||||
y0: s.bbox.y0,
|
y0: s.bbox.y0,
|
||||||
x1: s.bbox.x1,
|
x1: s.bbox.x1,
|
||||||
|
|||||||
41
frontend/wailsjs/wailsjs/go/ipc/Channel.d.ts
vendored
41
frontend/wailsjs/wailsjs/go/ipc/Channel.d.ts
vendored
@ -1,40 +1,41 @@
|
|||||||
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
||||||
// This file is automatically generated. DO NOT EDIT
|
// This file is automatically generated. DO NOT EDIT
|
||||||
|
import {entities} from '../models';
|
||||||
import {ipc} from '../models';
|
import {ipc} from '../models';
|
||||||
|
|
||||||
export function CreateNewProject(arg1:string):Promise<ipc.Session>;
|
export function CreateNewProject(arg1:string):Promise<entities.Session>;
|
||||||
|
|
||||||
export function GetAllLocalProjects():Promise<Array<ipc.Project>>;
|
export function GetAllLocalProjects():Promise<Array<entities.Project>>;
|
||||||
|
|
||||||
export function GetAreaById(arg1:string):Promise<ipc.Area>;
|
export function GetAreaById(arg1:string):Promise<entities.Area>;
|
||||||
|
|
||||||
export function GetCurrentSession():Promise<ipc.Session>;
|
export function GetCurrentSession():Promise<entities.Session>;
|
||||||
|
|
||||||
export function GetCurrentUser():Promise<ipc.User>;
|
export function GetCurrentUser():Promise<entities.User>;
|
||||||
|
|
||||||
export function GetDocumentById(arg1:string):Promise<ipc.Document>;
|
export function GetDocumentById(arg1:string):Promise<entities.Document>;
|
||||||
|
|
||||||
export function GetDocuments():Promise<ipc.GetDocumentsResponse>;
|
export function GetDocuments():Promise<ipc.GetDocumentsResponse>;
|
||||||
|
|
||||||
export function GetProcessedAreasByDocumentId(arg1:string):Promise<Array<ipc.ProcessedArea>>;
|
export function GetProcessedAreasByDocumentId(arg1:string):Promise<Array<entities.ProcessedArea>>;
|
||||||
|
|
||||||
export function GetProjectByName(arg1:string):Promise<ipc.Project>;
|
export function GetProjectByName(arg1:string):Promise<entities.Project>;
|
||||||
|
|
||||||
export function GetSuppportedLanguages():Promise<Array<ipc.Language>>;
|
export function GetSuppportedLanguages():Promise<Array<entities.Language>>;
|
||||||
|
|
||||||
export function GetUserMarkdownByDocumentId(arg1:string):Promise<ipc.UserMarkdown>;
|
export function GetUserMarkdownByDocumentId(arg1:string):Promise<entities.UserMarkdown>;
|
||||||
|
|
||||||
export function RequestAddArea(arg1:string,arg2:ipc.Area):Promise<ipc.Area>;
|
export function RequestAddArea(arg1:string,arg2:entities.Area):Promise<entities.Area>;
|
||||||
|
|
||||||
export function RequestAddDocument(arg1:string,arg2:string):Promise<ipc.Document>;
|
export function RequestAddDocument(arg1:string,arg2:string):Promise<entities.Document>;
|
||||||
|
|
||||||
export function RequestAddDocumentGroup(arg1:string):Promise<ipc.Group>;
|
export function RequestAddDocumentGroup(arg1:string):Promise<entities.Group>;
|
||||||
|
|
||||||
export function RequestAddProcessedArea(arg1:ipc.ProcessedArea):Promise<ipc.ProcessedArea>;
|
export function RequestAddProcessedArea(arg1:entities.ProcessedArea):Promise<entities.ProcessedArea>;
|
||||||
|
|
||||||
export function RequestChangeAreaOrder(arg1:string,arg2:number):Promise<ipc.Document>;
|
export function RequestChangeAreaOrder(arg1:string,arg2:number):Promise<entities.Document>;
|
||||||
|
|
||||||
export function RequestChangeGroupOrder(arg1:string,arg2:number):Promise<ipc.Group>;
|
export function RequestChangeGroupOrder(arg1:string,arg2:number):Promise<entities.Group>;
|
||||||
|
|
||||||
export function RequestChangeSessionProjectByName(arg1:string):Promise<boolean>;
|
export function RequestChangeSessionProjectByName(arg1:string):Promise<boolean>;
|
||||||
|
|
||||||
@ -52,12 +53,12 @@ export function RequestSaveLocalUserProcessedMarkdownCollection():Promise<boolea
|
|||||||
|
|
||||||
export function RequestSaveProcessedTextCollection():Promise<boolean>;
|
export function RequestSaveProcessedTextCollection():Promise<boolean>;
|
||||||
|
|
||||||
export function RequestUpdateArea(arg1:ipc.Area):Promise<ipc.Area>;
|
export function RequestUpdateArea(arg1:entities.Area):Promise<entities.Area>;
|
||||||
|
|
||||||
export function RequestUpdateCurrentUser(arg1:ipc.User):Promise<ipc.User>;
|
export function RequestUpdateCurrentUser(arg1:entities.User):Promise<entities.User>;
|
||||||
|
|
||||||
export function RequestUpdateDocument(arg1:ipc.Document):Promise<ipc.Document>;
|
export function RequestUpdateDocument(arg1:entities.Document):Promise<entities.Document>;
|
||||||
|
|
||||||
export function RequestUpdateDocumentUserMarkdown(arg1:string,arg2:string):Promise<ipc.UserMarkdown>;
|
export function RequestUpdateDocumentUserMarkdown(arg1:string,arg2:string):Promise<entities.UserMarkdown>;
|
||||||
|
|
||||||
export function RequestUpdateProcessedWordById(arg1:string,arg2:string):Promise<boolean>;
|
export function RequestUpdateProcessedWordById(arg1:string,arg2:string):Promise<boolean>;
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
export namespace ipc {
|
export namespace entities {
|
||||||
|
|
||||||
export class Language {
|
export class Language {
|
||||||
displayName: string;
|
displayName: string;
|
||||||
@ -122,39 +122,6 @@ export namespace ipc {
|
|||||||
this.order = source["order"];
|
this.order = source["order"];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export class GetDocumentsResponse {
|
|
||||||
documents: Document[];
|
|
||||||
groups: Group[];
|
|
||||||
|
|
||||||
static createFrom(source: any = {}) {
|
|
||||||
return new GetDocumentsResponse(source);
|
|
||||||
}
|
|
||||||
|
|
||||||
constructor(source: any = {}) {
|
|
||||||
if ('string' === typeof source) source = JSON.parse(source);
|
|
||||||
this.documents = this.convertValues(source["documents"], Document);
|
|
||||||
this.groups = this.convertValues(source["groups"], Group);
|
|
||||||
}
|
|
||||||
|
|
||||||
convertValues(a: any, classs: any, asMap: boolean = false): any {
|
|
||||||
if (!a) {
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
if (a.slice) {
|
|
||||||
return (a as any[]).map(elem => this.convertValues(elem, classs));
|
|
||||||
} else if ("object" === typeof a) {
|
|
||||||
if (asMap) {
|
|
||||||
for (const key of Object.keys(a)) {
|
|
||||||
a[key] = new classs(a[key]);
|
|
||||||
}
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
return new classs(a);
|
|
||||||
}
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
export class User {
|
export class User {
|
||||||
id: string;
|
id: string;
|
||||||
@ -507,3 +474,40 @@ export namespace ipc {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export namespace ipc {
|
||||||
|
|
||||||
|
export class GetDocumentsResponse {
|
||||||
|
documents: entities.Document[];
|
||||||
|
groups: entities.Group[];
|
||||||
|
|
||||||
|
static createFrom(source: any = {}) {
|
||||||
|
return new GetDocumentsResponse(source);
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(source: any = {}) {
|
||||||
|
if ('string' === typeof source) source = JSON.parse(source);
|
||||||
|
this.documents = this.convertValues(source["documents"], entities.Document);
|
||||||
|
this.groups = this.convertValues(source["groups"], entities.Group);
|
||||||
|
}
|
||||||
|
|
||||||
|
convertValues(a: any, classs: any, asMap: boolean = false): any {
|
||||||
|
if (!a) {
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
if (a.slice) {
|
||||||
|
return (a as any[]).map(elem => this.convertValues(elem, classs));
|
||||||
|
} else if ("object" === typeof a) {
|
||||||
|
if (asMap) {
|
||||||
|
for (const key of Object.keys(a)) {
|
||||||
|
a[key] = new classs(a[key]);
|
||||||
|
}
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
return new classs(a);
|
||||||
|
}
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
330
ipc/Documents.go
330
ipc/Documents.go
@ -3,47 +3,23 @@ package ipc
|
|||||||
import (
|
import (
|
||||||
"sort"
|
"sort"
|
||||||
app "textualize/core/App"
|
app "textualize/core/App"
|
||||||
consts "textualize/core/Consts"
|
|
||||||
document "textualize/core/Document"
|
document "textualize/core/Document"
|
||||||
session "textualize/core/Session"
|
session "textualize/core/Session"
|
||||||
|
"textualize/entities"
|
||||||
storage "textualize/storage"
|
storage "textualize/storage"
|
||||||
storageEntity "textualize/storage/Entities"
|
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
type GetDocumentsResponse struct {
|
type GetDocumentsResponse struct {
|
||||||
Documents []Document `json:"documents"`
|
Documents []entities.Document `json:"documents"`
|
||||||
Groups []Group `json:"groups"`
|
Groups []entities.Group `json:"groups"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Channel) GetDocumentById(id string) Document {
|
func (c *Channel) GetDocumentById(id string) entities.Document {
|
||||||
foundDocument := document.GetDocumentCollection().GetDocumentById(id)
|
foundDocument := document.GetDocumentCollection().GetDocumentById(id)
|
||||||
var jsonAreas []Area
|
return entities.Document(*foundDocument)
|
||||||
|
|
||||||
for _, a := range foundDocument.Areas {
|
|
||||||
jsonAreas = append(jsonAreas, Area{
|
|
||||||
Id: a.Id,
|
|
||||||
Name: a.Name,
|
|
||||||
StartX: a.StartX,
|
|
||||||
StartY: a.StartY,
|
|
||||||
EndX: a.EndX,
|
|
||||||
EndY: a.EndY,
|
|
||||||
Order: a.Order,
|
|
||||||
Language: Language(a.Language),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
response := Document{
|
|
||||||
Id: foundDocument.Id,
|
|
||||||
Name: foundDocument.Name,
|
|
||||||
GroupId: foundDocument.GroupId,
|
|
||||||
Path: foundDocument.Path,
|
|
||||||
ProjectId: foundDocument.ProjectId,
|
|
||||||
Areas: jsonAreas,
|
|
||||||
DefaultLanguage: Language(foundDocument.DefaultLanguage),
|
|
||||||
}
|
|
||||||
return response
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Channel) GetDocuments() GetDocumentsResponse {
|
func (c *Channel) GetDocuments() GetDocumentsResponse {
|
||||||
@ -51,63 +27,33 @@ func (c *Channel) GetDocuments() GetDocumentsResponse {
|
|||||||
groups := document.GetGroupCollection().Groups
|
groups := document.GetGroupCollection().Groups
|
||||||
|
|
||||||
response := GetDocumentsResponse{
|
response := GetDocumentsResponse{
|
||||||
Groups: make([]Group, 0),
|
Groups: make([]entities.Group, 0),
|
||||||
Documents: make([]Document, 0),
|
Documents: make([]entities.Document, 0),
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, d := range documents {
|
for _, d := range documents {
|
||||||
jsonAreas := make([]Area, 0)
|
sortedAreas := d.Areas
|
||||||
for _, a := range d.Areas {
|
sort.Slice(sortedAreas, func(i, j int) bool {
|
||||||
jsonAreas = append(jsonAreas, Area{
|
return sortedAreas[i].Order < sortedAreas[j].Order
|
||||||
Id: a.Id,
|
|
||||||
Name: a.Name,
|
|
||||||
StartX: a.StartX,
|
|
||||||
StartY: a.StartY,
|
|
||||||
EndX: a.EndX,
|
|
||||||
EndY: a.EndY,
|
|
||||||
Order: a.Order,
|
|
||||||
Language: Language(a.Language),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
sort.Slice(jsonAreas, func(i, j int) bool {
|
|
||||||
return jsonAreas[i].Order < jsonAreas[j].Order
|
|
||||||
})
|
})
|
||||||
|
|
||||||
jsonDocument := Document{
|
jsonDocument := entities.Document(d)
|
||||||
Id: d.Id,
|
d.Areas = sortedAreas
|
||||||
GroupId: d.GroupId,
|
|
||||||
Name: d.Name,
|
|
||||||
Path: d.Path,
|
|
||||||
ProjectId: d.ProjectId,
|
|
||||||
Areas: jsonAreas,
|
|
||||||
DefaultLanguage: Language(d.DefaultLanguage),
|
|
||||||
}
|
|
||||||
response.Documents = append(response.Documents, jsonDocument)
|
response.Documents = append(response.Documents, jsonDocument)
|
||||||
}
|
}
|
||||||
|
|
||||||
jsonGroups := make([]Group, 0)
|
if len(groups) > 0 {
|
||||||
for _, g := range groups {
|
sortedGroups := groups
|
||||||
jsonGroup := Group{
|
sort.Slice(sortedGroups, func(i, j int) bool {
|
||||||
Id: g.Id,
|
return sortedGroups[i].Order < sortedGroups[j].Order
|
||||||
ParentId: g.ParentId,
|
})
|
||||||
ProjectId: g.ProjectId,
|
response.Groups = sortedGroups
|
||||||
Name: g.Name,
|
|
||||||
Order: g.Order,
|
|
||||||
}
|
|
||||||
jsonGroups = append(jsonGroups, jsonGroup)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Slice(jsonGroups, func(i, j int) bool {
|
|
||||||
return jsonGroups[i].Order < jsonGroups[j].Order
|
|
||||||
})
|
|
||||||
|
|
||||||
response.Groups = jsonGroups
|
|
||||||
|
|
||||||
return response
|
return response
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Channel) RequestAddDocument(groupId string, documentName string) Document {
|
func (c *Channel) RequestAddDocument(groupId string, documentName string) entities.Document {
|
||||||
filePath, err := runtime.OpenFileDialog(app.GetInstance().Context, runtime.OpenDialogOptions{
|
filePath, err := runtime.OpenFileDialog(app.GetInstance().Context, runtime.OpenDialogOptions{
|
||||||
Title: "Select an Image",
|
Title: "Select an Image",
|
||||||
Filters: []runtime.FileFilter{
|
Filters: []runtime.FileFilter{
|
||||||
@ -120,7 +66,7 @@ func (c *Channel) RequestAddDocument(groupId string, documentName string) Docume
|
|||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
runtime.LogError(app.GetInstance().Context, err.Error())
|
runtime.LogError(app.GetInstance().Context, err.Error())
|
||||||
return Document{}
|
return entities.Document{}
|
||||||
}
|
}
|
||||||
|
|
||||||
newDocument := document.Entity{
|
newDocument := document.Entity{
|
||||||
@ -133,15 +79,7 @@ func (c *Channel) RequestAddDocument(groupId string, documentName string) Docume
|
|||||||
|
|
||||||
document.GetDocumentCollection().AddDocument(newDocument)
|
document.GetDocumentCollection().AddDocument(newDocument)
|
||||||
|
|
||||||
documentResponse := Document{
|
return entities.Document(newDocument)
|
||||||
Id: newDocument.Id,
|
|
||||||
Name: newDocument.Name,
|
|
||||||
Path: newDocument.Path,
|
|
||||||
GroupId: newDocument.GroupId,
|
|
||||||
ProjectId: newDocument.ProjectId,
|
|
||||||
}
|
|
||||||
|
|
||||||
return documentResponse
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Channel) deleteDocumentById(documentId string) bool {
|
func (c *Channel) deleteDocumentById(documentId string) bool {
|
||||||
@ -164,11 +102,11 @@ func (c *Channel) deleteDocumentById(documentId string) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Channel) RequestUpdateDocumentUserMarkdown(documentId string, markdown string) UserMarkdown {
|
func (c *Channel) RequestUpdateDocumentUserMarkdown(documentId string, markdown string) entities.UserMarkdown {
|
||||||
markdownCollection := document.GetUserMarkdownCollection()
|
markdownCollection := document.GetUserMarkdownCollection()
|
||||||
markdownToUpdate := markdownCollection.GetUserMarkdownByDocumentId(documentId)
|
markdownToUpdate := markdownCollection.GetUserMarkdownByDocumentId(documentId)
|
||||||
|
|
||||||
newMarkdown := document.UserMarkdown{
|
newMarkdown := entities.UserMarkdown{
|
||||||
DocumentId: documentId,
|
DocumentId: documentId,
|
||||||
Value: markdown,
|
Value: markdown,
|
||||||
}
|
}
|
||||||
@ -179,11 +117,7 @@ func (c *Channel) RequestUpdateDocumentUserMarkdown(documentId string, markdown
|
|||||||
}
|
}
|
||||||
|
|
||||||
updatedMarkdown := markdownCollection.UpdateUserMarkdown(newMarkdown)
|
updatedMarkdown := markdownCollection.UpdateUserMarkdown(newMarkdown)
|
||||||
return UserMarkdown{
|
return entities.UserMarkdown(updatedMarkdown)
|
||||||
Id: updatedMarkdown.Id,
|
|
||||||
DocumentId: updatedMarkdown.DocumentId,
|
|
||||||
Value: updatedMarkdown.Value,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Channel) deleteDocumentUserMarkdown(documentId string) bool {
|
func (c *Channel) deleteDocumentUserMarkdown(documentId string) bool {
|
||||||
@ -206,26 +140,15 @@ func (c *Channel) deleteDocumentUserMarkdown(documentId string) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Channel) GetUserMarkdownByDocumentId(documentId string) UserMarkdown {
|
func (c *Channel) GetUserMarkdownByDocumentId(documentId string) entities.UserMarkdown {
|
||||||
foundUserMarkdown := document.GetUserMarkdownCollection().GetUserMarkdownByDocumentId((documentId))
|
foundUserMarkdown := document.GetUserMarkdownCollection().GetUserMarkdownByDocumentId((documentId))
|
||||||
|
return entities.UserMarkdown(*foundUserMarkdown)
|
||||||
response := UserMarkdown{}
|
|
||||||
|
|
||||||
if foundUserMarkdown != nil {
|
|
||||||
response = UserMarkdown{
|
|
||||||
Id: foundUserMarkdown.Id,
|
|
||||||
DocumentId: foundUserMarkdown.DocumentId,
|
|
||||||
Value: foundUserMarkdown.Value,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return response
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Channel) RequestAddDocumentGroup(name string) Group {
|
func (c *Channel) RequestAddDocumentGroup(name string) entities.Group {
|
||||||
groupCollection := document.GetGroupCollection()
|
groupCollection := document.GetGroupCollection()
|
||||||
|
|
||||||
newGroup := document.Group{
|
newGroup := entities.Group{
|
||||||
Id: uuid.NewString(),
|
Id: uuid.NewString(),
|
||||||
Name: name,
|
Name: name,
|
||||||
ProjectId: session.GetInstance().Project.Id,
|
ProjectId: session.GetInstance().Project.Id,
|
||||||
@ -234,60 +157,41 @@ func (c *Channel) RequestAddDocumentGroup(name string) Group {
|
|||||||
|
|
||||||
groupCollection.AddDocumentGroup(newGroup)
|
groupCollection.AddDocumentGroup(newGroup)
|
||||||
|
|
||||||
response := Group{
|
return newGroup
|
||||||
Id: newGroup.Id,
|
|
||||||
Name: newGroup.Name,
|
|
||||||
ParentId: newGroup.ParentId,
|
|
||||||
ProjectId: newGroup.ProjectId,
|
|
||||||
Order: newGroup.Order,
|
|
||||||
}
|
|
||||||
|
|
||||||
return response
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Channel) RequestChangeGroupOrder(groupId string, newOrder int) Group {
|
func (c *Channel) RequestChangeGroupOrder(groupId string, newOrder int) entities.Group {
|
||||||
groupCollection := document.GetGroupCollection()
|
groupCollection := document.GetGroupCollection()
|
||||||
|
|
||||||
for _, g := range groupCollection.Groups {
|
for _, g := range groupCollection.Groups {
|
||||||
if g.Id == groupId {
|
if g.Id == groupId {
|
||||||
// document.GetGroupCollection().Groups[index].Order = newOrder
|
|
||||||
document.GetGroupCollection().GetGroupById(groupId).Order = newOrder
|
document.GetGroupCollection().GetGroupById(groupId).Order = newOrder
|
||||||
} else if g.Order >= newOrder {
|
} else if g.Order >= newOrder {
|
||||||
// document.GetGroupCollection().Groups[index].Order = g.Order + 1
|
|
||||||
document.GetGroupCollection().GetGroupById(groupId).Order = g.Order + 1
|
document.GetGroupCollection().GetGroupById(groupId).Order = g.Order + 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Group(*document.GetGroupCollection().GetGroupById(groupId))
|
return *document.GetGroupCollection().GetGroupById(groupId)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Channel) GetAreaById(areaId string) Area {
|
func (c *Channel) GetAreaById(areaId string) entities.Area {
|
||||||
foundDocument := document.GetDocumentCollection().GetDocumentByAreaId(areaId)
|
foundDocument := document.GetDocumentCollection().GetDocumentByAreaId(areaId)
|
||||||
|
|
||||||
if len(foundDocument.Areas) == 0 {
|
if len(foundDocument.Areas) == 0 {
|
||||||
return Area{}
|
return entities.Area{}
|
||||||
}
|
}
|
||||||
|
|
||||||
var foundArea document.Area
|
var foundArea entities.Area
|
||||||
for i, a := range foundDocument.Areas {
|
for i, a := range foundDocument.Areas {
|
||||||
if a.Id == areaId {
|
if a.Id == areaId {
|
||||||
foundArea = foundDocument.Areas[i]
|
foundArea = foundDocument.Areas[i]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Area{
|
return foundArea
|
||||||
Id: foundArea.Id,
|
|
||||||
Name: foundArea.Name,
|
|
||||||
StartX: foundArea.StartX,
|
|
||||||
EndX: foundArea.EndX,
|
|
||||||
StartY: foundArea.StartY,
|
|
||||||
EndY: foundArea.EndY,
|
|
||||||
Order: foundArea.Order,
|
|
||||||
Language: Language(foundArea.Language),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Channel) RequestAddArea(documentId string, area Area) Area {
|
func (c *Channel) RequestAddArea(documentId string, area entities.Area) entities.Area {
|
||||||
foundDocument := document.GetDocumentCollection().GetDocumentById(documentId)
|
foundDocument := document.GetDocumentCollection().GetDocumentById(documentId)
|
||||||
|
|
||||||
var id string
|
var id string
|
||||||
@ -302,7 +206,7 @@ func (c *Channel) RequestAddArea(documentId string, area Area) Area {
|
|||||||
order = len(foundDocument.Areas)
|
order = len(foundDocument.Areas)
|
||||||
}
|
}
|
||||||
|
|
||||||
newArea := document.Area{
|
newArea := entities.Area{
|
||||||
Id: id,
|
Id: id,
|
||||||
Name: area.Name,
|
Name: area.Name,
|
||||||
StartX: area.StartX,
|
StartX: area.StartX,
|
||||||
@ -310,30 +214,26 @@ func (c *Channel) RequestAddArea(documentId string, area Area) Area {
|
|||||||
StartY: area.StartY,
|
StartY: area.StartY,
|
||||||
EndY: area.EndY,
|
EndY: area.EndY,
|
||||||
Order: order,
|
Order: order,
|
||||||
Language: consts.Language(area.Language),
|
Language: entities.Language(area.Language),
|
||||||
}
|
}
|
||||||
foundDocument.AddArea(newArea)
|
foundDocument.AddArea(newArea)
|
||||||
|
|
||||||
responseArea := area
|
return newArea
|
||||||
responseArea.Id = id
|
|
||||||
|
|
||||||
return responseArea
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Channel) RequestUpdateArea(updatedArea Area) Area {
|
func (c *Channel) RequestUpdateArea(updatedArea entities.Area) entities.Area {
|
||||||
documentOfArea := document.GetDocumentCollection().GetDocumentByAreaId(updatedArea.Id)
|
documentOfArea := document.GetDocumentCollection().GetDocumentByAreaId(updatedArea.Id)
|
||||||
|
|
||||||
if documentOfArea.Id == "" {
|
if documentOfArea.Id == "" {
|
||||||
return Area{}
|
return entities.Area{}
|
||||||
}
|
}
|
||||||
|
|
||||||
areaToUpdate := documentOfArea.GetAreaById(updatedArea.Id)
|
areaToUpdate := documentOfArea.GetAreaById(updatedArea.Id)
|
||||||
|
|
||||||
if areaToUpdate.Id == "" {
|
if areaToUpdate.Id == "" {
|
||||||
return Area{}
|
return entities.Area{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: add more prop changes when needed
|
|
||||||
if updatedArea.Name != "" {
|
if updatedArea.Name != "" {
|
||||||
areaToUpdate.Name = updatedArea.Name
|
areaToUpdate.Name = updatedArea.Name
|
||||||
}
|
}
|
||||||
@ -341,16 +241,7 @@ func (c *Channel) RequestUpdateArea(updatedArea Area) Area {
|
|||||||
areaToUpdate.Order = updatedArea.Order
|
areaToUpdate.Order = updatedArea.Order
|
||||||
}
|
}
|
||||||
|
|
||||||
return Area{
|
return *areaToUpdate
|
||||||
Id: areaToUpdate.Id,
|
|
||||||
Name: areaToUpdate.Name,
|
|
||||||
StartX: areaToUpdate.StartX,
|
|
||||||
StartY: areaToUpdate.StartY,
|
|
||||||
EndX: areaToUpdate.EndX,
|
|
||||||
EndY: areaToUpdate.EndY,
|
|
||||||
Order: areaToUpdate.Order,
|
|
||||||
Language: Language(areaToUpdate.Language),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Channel) RequestDeleteAreaById(areaId string) bool {
|
func (c *Channel) RequestDeleteAreaById(areaId string) bool {
|
||||||
@ -379,11 +270,11 @@ func (c *Channel) RequestDeleteAreaById(areaId string) bool {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Channel) RequestUpdateDocument(updatedDocument Document) Document {
|
func (c *Channel) RequestUpdateDocument(updatedDocument entities.Document) entities.Document {
|
||||||
documentToUpdate := document.GetDocumentCollection().GetDocumentById(updatedDocument.Id)
|
documentToUpdate := document.GetDocumentCollection().GetDocumentById(updatedDocument.Id)
|
||||||
|
|
||||||
if documentToUpdate == nil {
|
if documentToUpdate == nil {
|
||||||
return Document{}
|
return entities.Document{}
|
||||||
}
|
}
|
||||||
|
|
||||||
if updatedDocument.Id != "" {
|
if updatedDocument.Id != "" {
|
||||||
@ -399,20 +290,20 @@ func (c *Channel) RequestUpdateDocument(updatedDocument Document) Document {
|
|||||||
documentToUpdate.Path = updatedDocument.Path
|
documentToUpdate.Path = updatedDocument.Path
|
||||||
}
|
}
|
||||||
if updatedDocument.DefaultLanguage.DisplayName != "" {
|
if updatedDocument.DefaultLanguage.DisplayName != "" {
|
||||||
documentToUpdate.DefaultLanguage = consts.Language(updatedDocument.DefaultLanguage)
|
documentToUpdate.DefaultLanguage = updatedDocument.DefaultLanguage
|
||||||
}
|
}
|
||||||
|
|
||||||
return updatedDocument
|
return updatedDocument
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Channel) RequestChangeAreaOrder(areaId string, newOrder int) Document {
|
func (c *Channel) RequestChangeAreaOrder(areaId string, newOrder int) entities.Document {
|
||||||
documentOfArea := document.GetDocumentCollection().GetDocumentByAreaId((areaId))
|
documentOfArea := document.GetDocumentCollection().GetDocumentByAreaId((areaId))
|
||||||
|
|
||||||
if documentOfArea == nil {
|
if documentOfArea == nil {
|
||||||
return Document{}
|
return entities.Document{}
|
||||||
}
|
}
|
||||||
|
|
||||||
var foundArea document.Area
|
var foundArea entities.Area
|
||||||
for _, a := range documentOfArea.Areas {
|
for _, a := range documentOfArea.Areas {
|
||||||
if a.Id == areaId {
|
if a.Id == areaId {
|
||||||
foundArea = a
|
foundArea = a
|
||||||
@ -421,7 +312,7 @@ func (c *Channel) RequestChangeAreaOrder(areaId string, newOrder int) Document {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if foundArea.Id == "" {
|
if foundArea.Id == "" {
|
||||||
return Document{}
|
return entities.Document{}
|
||||||
}
|
}
|
||||||
|
|
||||||
processedAreasCollection := document.GetProcessedAreaCollection()
|
processedAreasCollection := document.GetProcessedAreaCollection()
|
||||||
@ -455,37 +346,18 @@ func (c *Channel) RequestSaveDocumentCollection() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
var documentsToWrite []storageEntity.Document
|
documentCount := len(documentCollection.Documents)
|
||||||
for _, d := range documentCollection.Documents {
|
writableDocuments := make([]entities.Document, documentCount)
|
||||||
var areasToWrite []storageEntity.Area
|
for i := 0; i < documentCount; i++ {
|
||||||
for _, a := range d.Areas {
|
writableDocuments[i] = entities.Document(documentCollection.Documents[i])
|
||||||
areasToWrite = append(areasToWrite, storageEntity.Area{
|
|
||||||
Id: a.Id,
|
|
||||||
Name: a.Name,
|
|
||||||
StartX: a.StartX,
|
|
||||||
StartY: a.StartY,
|
|
||||||
EndX: a.EndX,
|
|
||||||
EndY: a.EndY,
|
|
||||||
Language: storageEntity.Language(a.Language),
|
|
||||||
Order: a.Order,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
documentsToWrite = append(documentsToWrite, storageEntity.Document{
|
|
||||||
Id: d.Id,
|
|
||||||
GroupId: d.GroupId,
|
|
||||||
Name: d.Name,
|
|
||||||
Path: d.Path,
|
|
||||||
ProjectId: d.ProjectId,
|
|
||||||
Areas: areasToWrite,
|
|
||||||
DefaultLanguage: storageEntity.Language(d.DefaultLanguage),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
successfulWrite := storage.GetDriver().WriteDocumentCollection(storageEntity.DocumentCollection{
|
successfulWrite := storage.GetDriver().WriteDocumentCollection(
|
||||||
Documents: documentsToWrite,
|
entities.DocumentCollection{
|
||||||
ProjectId: fullProject.Id,
|
ProjectId: fullProject.Id,
|
||||||
}, projectName)
|
Documents: writableDocuments,
|
||||||
|
},
|
||||||
|
projectName)
|
||||||
|
|
||||||
return successfulWrite
|
return successfulWrite
|
||||||
}
|
}
|
||||||
@ -500,15 +372,16 @@ func (c *Channel) RequestSaveGroupCollection() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
var groupsToWrite []storageEntity.Group
|
groupCount := len(groupCollection.Groups)
|
||||||
for _, g := range groupCollection.Groups {
|
writableGroups := make([]entities.Group, groupCount)
|
||||||
groupsToWrite = append(groupsToWrite, storageEntity.Group(g))
|
for i := 0; i < groupCount; i++ {
|
||||||
|
writableGroups[i] = entities.Group(groupCollection.Groups[i])
|
||||||
}
|
}
|
||||||
|
|
||||||
successfulWrite := storage.GetDriver().WriteGroupCollection(storageEntity.GroupCollection{
|
successfulWrite := storage.GetDriver().WriteGroupCollection(entities.GroupCollection{
|
||||||
Id: groupCollection.Id,
|
Id: groupCollection.Id,
|
||||||
ProjectId: groupCollection.ProjectId,
|
ProjectId: groupCollection.ProjectId,
|
||||||
Groups: groupsToWrite,
|
Groups: writableGroups,
|
||||||
}, projectName)
|
}, projectName)
|
||||||
|
|
||||||
return successfulWrite
|
return successfulWrite
|
||||||
@ -518,53 +391,18 @@ func (c *Channel) RequestSaveProcessedTextCollection() bool {
|
|||||||
processedAreaCollection := document.GetProcessedAreaCollection()
|
processedAreaCollection := document.GetProcessedAreaCollection()
|
||||||
projectName := c.GetCurrentSession().Project.Name
|
projectName := c.GetCurrentSession().Project.Name
|
||||||
|
|
||||||
areasToWrite := make([]storageEntity.ProcessedArea, 0)
|
processedAreasCount := len(processedAreaCollection.Areas)
|
||||||
for _, a := range processedAreaCollection.Areas {
|
writableProcessedAreasAreas := make([]entities.ProcessedArea, processedAreasCount)
|
||||||
linesOfAreaToWrite := make([]storageEntity.ProcessedLine, 0)
|
for i := 0; i < processedAreasCount; i++ {
|
||||||
for _, l := range a.Lines {
|
writableProcessedAreasAreas[i] = entities.ProcessedArea(processedAreaCollection.Areas[i])
|
||||||
wordsOfLineToWrite := make([]storageEntity.ProcessedWord, 0)
|
|
||||||
|
|
||||||
for _, w := range l.Words {
|
|
||||||
symbolsOfWordToWrite := make([]storageEntity.ProcessedSymbol, 0)
|
|
||||||
|
|
||||||
for _, s := range w.Symbols {
|
|
||||||
symbolsOfWordToWrite = append(symbolsOfWordToWrite, storageEntity.ProcessedSymbol{
|
|
||||||
Text: s.Text,
|
|
||||||
Confidence: s.Confidence,
|
|
||||||
BoundingBox: storageEntity.ProcessedBoundingBox(s.BoundingBox),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
wordsOfLineToWrite = append(wordsOfLineToWrite, storageEntity.ProcessedWord{
|
|
||||||
Id: w.Id,
|
|
||||||
FullText: w.FullText,
|
|
||||||
Confidence: w.Confidence,
|
|
||||||
Direction: w.Direction,
|
|
||||||
BoundingBox: storageEntity.ProcessedBoundingBox(w.BoundingBox),
|
|
||||||
Symbols: symbolsOfWordToWrite,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
linesOfAreaToWrite = append(linesOfAreaToWrite, storageEntity.ProcessedLine{
|
|
||||||
FullText: l.FullText,
|
|
||||||
Words: wordsOfLineToWrite,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
areasToWrite = append(areasToWrite, storageEntity.ProcessedArea{
|
|
||||||
Id: a.Id,
|
|
||||||
DocumentId: a.DocumentId,
|
|
||||||
FullText: a.FullText,
|
|
||||||
Order: a.Order,
|
|
||||||
Lines: linesOfAreaToWrite,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
processedAreaCollectionToWrite := storageEntity.ProcessedTextCollection{
|
successfulWrite := storage.GetDriver().WriteProcessedTextCollection(
|
||||||
Areas: areasToWrite,
|
entities.ProcessedTextCollection{
|
||||||
}
|
Areas: writableProcessedAreasAreas,
|
||||||
|
},
|
||||||
successfulWrite := storage.GetDriver().WriteProcessedTextCollection(processedAreaCollectionToWrite, projectName)
|
projectName,
|
||||||
|
)
|
||||||
return successfulWrite
|
return successfulWrite
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -578,14 +416,18 @@ func (c *Channel) RequestSaveLocalUserProcessedMarkdownCollection() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
var valuesToWrite []storageEntity.ProcessedUserMarkdown
|
groupCount := len(userProcessedMarkdownCollection.Values)
|
||||||
for _, v := range userProcessedMarkdownCollection.Values {
|
writableMarkdownValues := make([]entities.ProcessedUserMarkdown, groupCount)
|
||||||
valuesToWrite = append(valuesToWrite, storageEntity.ProcessedUserMarkdown(v))
|
for i := 0; i < groupCount; i++ {
|
||||||
|
writableMarkdownValues[i] = entities.ProcessedUserMarkdown(userProcessedMarkdownCollection.Values[i])
|
||||||
}
|
}
|
||||||
|
|
||||||
successfulWrite := storage.GetDriver().WriteProcessedUserMarkdownCollection(storageEntity.ProcessedUserMarkdownCollection{
|
successfulWrite := storage.GetDriver().WriteProcessedUserMarkdownCollection(
|
||||||
Values: valuesToWrite,
|
entities.ProcessedUserMarkdownCollection{
|
||||||
}, projectName)
|
Values: writableMarkdownValues,
|
||||||
|
},
|
||||||
|
projectName,
|
||||||
|
)
|
||||||
|
|
||||||
return successfulWrite
|
return successfulWrite
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,128 +0,0 @@
|
|||||||
package ipc
|
|
||||||
|
|
||||||
type Document struct {
|
|
||||||
Id string `json:"id"`
|
|
||||||
GroupId string `json:"groupId"`
|
|
||||||
Name string `json:"name"`
|
|
||||||
Path string `json:"path"`
|
|
||||||
ProjectId string `json:"projectId"`
|
|
||||||
Areas []Area `json:"areas"`
|
|
||||||
DefaultLanguage Language `json:"defaultLanguage"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type DocumentCollection struct {
|
|
||||||
Documents []Document `json:"documents"`
|
|
||||||
ProjectId string `json:"projectId"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Group struct {
|
|
||||||
Id string `json:"id"`
|
|
||||||
ParentId string `json:"parentId"`
|
|
||||||
ProjectId string `json:"projectId"`
|
|
||||||
Name string `json:"name"`
|
|
||||||
Order int `json:"order"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type GroupCollection struct {
|
|
||||||
Id string `json:"id"`
|
|
||||||
Groups []Group `json:"groups"`
|
|
||||||
ProjectId string `json:"projectId"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Area struct {
|
|
||||||
Id string `json:"id"`
|
|
||||||
Name string `json:"name"`
|
|
||||||
StartX int `json:"startX"`
|
|
||||||
StartY int `json:"startY"`
|
|
||||||
EndX int `json:"endX"`
|
|
||||||
EndY int `json:"endY"`
|
|
||||||
Language Language `json:"language"`
|
|
||||||
Order int `json:"order"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ProcessedBoundingBox struct {
|
|
||||||
X0 int32 `json:"x0"`
|
|
||||||
Y0 int32 `json:"y0"`
|
|
||||||
X1 int32 `json:"x1"`
|
|
||||||
Y1 int32 `json:"y1"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ProcessedSymbol struct {
|
|
||||||
Text string `json:"text"`
|
|
||||||
Confidence float32 `json:"confidence"`
|
|
||||||
BoundingBox ProcessedBoundingBox `json:"boundingBox"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ProcessedWord struct {
|
|
||||||
Id string `json:"id"`
|
|
||||||
FullText string `json:"fullText"`
|
|
||||||
Symbols []ProcessedSymbol `json:"symbols"`
|
|
||||||
Confidence float32 `json:"confidence"`
|
|
||||||
Direction string `json:"direction"`
|
|
||||||
BoundingBox ProcessedBoundingBox `json:"boundingBox"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ProcessedLine struct {
|
|
||||||
FullText string `json:"fullText"`
|
|
||||||
Words []ProcessedWord `json:"words"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ProcessedArea struct {
|
|
||||||
Id string `json:"id"`
|
|
||||||
DocumentId string `json:"documentId"`
|
|
||||||
FullText string `json:"fullText"`
|
|
||||||
Order int `json:"order"`
|
|
||||||
Lines []ProcessedLine `json:"lines"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type UserMarkdown struct {
|
|
||||||
Id string `json:"id"`
|
|
||||||
DocumentId string `json:"documentId"`
|
|
||||||
Value string `json:"value"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type UserMarkdownCollection struct {
|
|
||||||
Values []UserMarkdown `json:"values"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type User struct {
|
|
||||||
Id string `json:"id"`
|
|
||||||
LocalId string `json:"localId"`
|
|
||||||
FirstName string `json:"firstName"`
|
|
||||||
LastName string `json:"lastName"`
|
|
||||||
AvatarPath string `json:"avatarPath"`
|
|
||||||
AuthToken string `json:"authToken"`
|
|
||||||
Email string `json:"email"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Organization struct {
|
|
||||||
Id string `json:"id"`
|
|
||||||
Name string `json:"name"`
|
|
||||||
LogoPath string `json:"logoPath"`
|
|
||||||
Users []User `json:"users"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Project struct {
|
|
||||||
Id string `json:"id"`
|
|
||||||
OrganizationId string `json:"organizationId"`
|
|
||||||
Name string `json:"name"`
|
|
||||||
Settings ProjectSettings `json:"settings"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ProjectSettings struct {
|
|
||||||
DefaultProcessLanguage Language `json:"defaultProcessLanguage"`
|
|
||||||
DefaultTranslateTargetLanguage Language `json:"defaultTranslateTargetLanguage"`
|
|
||||||
IsHosted bool `json:"isHosted"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Session struct {
|
|
||||||
Project Project `json:"project"`
|
|
||||||
Organization Organization `json:"organization"`
|
|
||||||
User User `json:"user"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Language struct {
|
|
||||||
DisplayName string `json:"displayName"`
|
|
||||||
ProcessCode string `json:"processCode"`
|
|
||||||
TranslateCode string `json:"translateCode"`
|
|
||||||
}
|
|
||||||
@ -3,180 +3,39 @@ package ipc
|
|||||||
import (
|
import (
|
||||||
"sort"
|
"sort"
|
||||||
document "textualize/core/Document"
|
document "textualize/core/Document"
|
||||||
|
"textualize/entities"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
func serializeBoundingBox(bbox document.ProcessedBoundingBox) ProcessedBoundingBox {
|
func (c *Channel) GetProcessedAreasByDocumentId(id string) []entities.ProcessedArea {
|
||||||
return ProcessedBoundingBox{
|
|
||||||
X0: bbox.X0,
|
|
||||||
Y0: bbox.Y0,
|
|
||||||
X1: bbox.X1,
|
|
||||||
Y1: bbox.Y1,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func serializeSymbol(symbol document.ProcessedSymbol) ProcessedSymbol {
|
|
||||||
return ProcessedSymbol{
|
|
||||||
Text: symbol.Text,
|
|
||||||
Confidence: symbol.Confidence,
|
|
||||||
BoundingBox: serializeBoundingBox(symbol.BoundingBox),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func serialzeWord(word document.ProcessedWord) ProcessedWord {
|
|
||||||
var symbols []ProcessedSymbol
|
|
||||||
|
|
||||||
for _, symbol := range word.Symbols {
|
|
||||||
symbols = append(symbols, serializeSymbol(symbol))
|
|
||||||
}
|
|
||||||
|
|
||||||
return ProcessedWord{
|
|
||||||
Id: word.Id,
|
|
||||||
FullText: word.FullText,
|
|
||||||
Symbols: symbols,
|
|
||||||
Confidence: word.Confidence,
|
|
||||||
Direction: word.Direction,
|
|
||||||
BoundingBox: serializeBoundingBox(word.BoundingBox),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func serializeLine(line document.ProcessedLine) ProcessedLine {
|
|
||||||
var words []ProcessedWord
|
|
||||||
|
|
||||||
for _, word := range line.Words {
|
|
||||||
words = append(words, serialzeWord((word)))
|
|
||||||
}
|
|
||||||
|
|
||||||
return ProcessedLine{
|
|
||||||
FullText: line.FullText,
|
|
||||||
Words: words,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func serializeProcessedArea(area document.ProcessedArea) ProcessedArea {
|
|
||||||
var lines []ProcessedLine
|
|
||||||
|
|
||||||
for _, line := range area.Lines {
|
|
||||||
lines = append(lines, serializeLine(line))
|
|
||||||
}
|
|
||||||
|
|
||||||
return ProcessedArea{
|
|
||||||
Id: area.Id,
|
|
||||||
DocumentId: area.DocumentId,
|
|
||||||
FullText: area.FullText,
|
|
||||||
Order: area.Order,
|
|
||||||
Lines: lines,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Channel) GetProcessedAreasByDocumentId(id string) []ProcessedArea {
|
|
||||||
areas := document.GetProcessedAreaCollection().GetAreasByDocumentId(id)
|
areas := document.GetProcessedAreaCollection().GetAreasByDocumentId(id)
|
||||||
|
|
||||||
var response []ProcessedArea
|
areaCount := len(areas)
|
||||||
|
readableAreas := make([]entities.ProcessedArea, areaCount)
|
||||||
for _, a := range areas {
|
for i := 0; i < areaCount; i++ {
|
||||||
response = append(response, serializeProcessedArea(*a))
|
readableAreas[i] = entities.ProcessedArea(*areas[i])
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Slice(response, func(i, j int) bool {
|
sortedAreas := readableAreas
|
||||||
return response[i].Order < response[j].Order
|
sort.Slice(sortedAreas, func(i, j int) bool {
|
||||||
|
return sortedAreas[i].Order < sortedAreas[j].Order
|
||||||
})
|
})
|
||||||
|
|
||||||
return response
|
return sortedAreas
|
||||||
}
|
}
|
||||||
|
|
||||||
func deserializeBoundingBox(bbox ProcessedBoundingBox) document.ProcessedBoundingBox {
|
func (c *Channel) RequestAddProcessedArea(processedArea entities.ProcessedArea) entities.ProcessedArea {
|
||||||
return document.ProcessedBoundingBox{
|
|
||||||
X0: bbox.X0,
|
|
||||||
Y0: bbox.Y0,
|
|
||||||
X1: bbox.X1,
|
|
||||||
Y1: bbox.Y1,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func deserializeSymbol(symbol ProcessedSymbol) document.ProcessedSymbol {
|
for lineIndex, line := range processedArea.Lines {
|
||||||
return document.ProcessedSymbol{
|
for wordIndex, word := range line.Words {
|
||||||
Text: symbol.Text,
|
if word.Id == "" {
|
||||||
Confidence: symbol.Confidence,
|
processedArea.Lines[lineIndex].Words[wordIndex].Id = uuid.NewString()
|
||||||
BoundingBox: deserializeBoundingBox(symbol.BoundingBox),
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
func deserialzeWord(word ProcessedWord) document.ProcessedWord {
|
|
||||||
var symbols []document.ProcessedSymbol
|
|
||||||
|
|
||||||
for _, symbol := range word.Symbols {
|
|
||||||
symbols = append(symbols, deserializeSymbol(symbol))
|
|
||||||
}
|
|
||||||
var wordId string
|
|
||||||
if word.Id == "" {
|
|
||||||
wordId = uuid.NewString()
|
|
||||||
} else {
|
|
||||||
wordId = word.Id
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return document.ProcessedWord{
|
document.GetProcessedAreaCollection().AddProcessedArea(processedArea)
|
||||||
Id: wordId,
|
|
||||||
FullText: word.FullText,
|
|
||||||
Symbols: symbols,
|
|
||||||
Confidence: word.Confidence,
|
|
||||||
Direction: word.Direction,
|
|
||||||
BoundingBox: deserializeBoundingBox(word.BoundingBox),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func deserializeLine(line ProcessedLine) document.ProcessedLine {
|
|
||||||
var words []document.ProcessedWord
|
|
||||||
|
|
||||||
for _, word := range line.Words {
|
|
||||||
words = append(words, deserialzeWord((word)))
|
|
||||||
}
|
|
||||||
|
|
||||||
return document.ProcessedLine{
|
|
||||||
FullText: line.FullText,
|
|
||||||
Words: words,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func deserializeProcessedArea(area ProcessedArea) document.ProcessedArea {
|
|
||||||
var lines []document.ProcessedLine
|
|
||||||
|
|
||||||
for _, line := range area.Lines {
|
|
||||||
lines = append(lines, deserializeLine(line))
|
|
||||||
}
|
|
||||||
|
|
||||||
return document.ProcessedArea{
|
|
||||||
Id: area.Id,
|
|
||||||
DocumentId: area.DocumentId,
|
|
||||||
Order: area.Order,
|
|
||||||
FullText: area.FullText,
|
|
||||||
Lines: lines,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Channel) RequestAddProcessedArea(processedArea ProcessedArea) ProcessedArea {
|
|
||||||
// doesAreaAlreadyExist := false
|
|
||||||
// processedAreasOfDocuments := document.GetProcessedAreaCollection().GetAreasByDocumentId(processedArea.DocumentId)
|
|
||||||
|
|
||||||
// for _, a := range processedAreasOfDocuments {
|
|
||||||
// if a.Order == processedArea.Order {
|
|
||||||
// doesAreaAlreadyExist = true
|
|
||||||
// break
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
deserializedProcessedArea := deserializeProcessedArea(processedArea)
|
|
||||||
|
|
||||||
// if doesAreaAlreadyExist {
|
|
||||||
// storedProcessedArea := document.GetProcessedAreaCollection().GetAreaById(processedArea.Id)
|
|
||||||
// if storedProcessedArea.Id != "" {
|
|
||||||
// storedProcessedArea = &deserializedProcessedArea
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
document.GetProcessedAreaCollection().AddProcessedArea((deserializedProcessedArea))
|
|
||||||
// }
|
|
||||||
|
|
||||||
return processedArea
|
return processedArea
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -214,7 +73,7 @@ func (c *Channel) RequestUpdateProcessedWordById(wordId string, newTextValue str
|
|||||||
}
|
}
|
||||||
|
|
||||||
wordProps := areas[areaOfWordIndex].Lines[lineOfWordIndex].Words[foundWordIndex]
|
wordProps := areas[areaOfWordIndex].Lines[lineOfWordIndex].Words[foundWordIndex]
|
||||||
areas[areaOfWordIndex].Lines[lineOfWordIndex].Words[foundWordIndex] = document.ProcessedWord{
|
areas[areaOfWordIndex].Lines[lineOfWordIndex].Words[foundWordIndex] = entities.ProcessedWord{
|
||||||
Id: wordProps.Id,
|
Id: wordProps.Id,
|
||||||
Direction: wordProps.Direction,
|
Direction: wordProps.Direction,
|
||||||
FullText: newTextValue,
|
FullText: newTextValue,
|
||||||
|
|||||||
219
ipc/Session.go
219
ipc/Session.go
@ -5,40 +5,40 @@ import (
|
|||||||
consts "textualize/core/Consts"
|
consts "textualize/core/Consts"
|
||||||
document "textualize/core/Document"
|
document "textualize/core/Document"
|
||||||
session "textualize/core/Session"
|
session "textualize/core/Session"
|
||||||
|
"textualize/entities"
|
||||||
storage "textualize/storage"
|
storage "textualize/storage"
|
||||||
storageEntity "textualize/storage/Entities"
|
|
||||||
|
|
||||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *Channel) GetCurrentSession() Session {
|
func (c *Channel) GetCurrentSession() entities.Session {
|
||||||
currentSession := session.GetInstance()
|
currentSession := session.GetInstance()
|
||||||
|
|
||||||
var sessionUsers []User
|
var sessionUsers []entities.User
|
||||||
for _, u := range currentSession.Organization.Users {
|
for _, u := range currentSession.Organization.Users {
|
||||||
sessionUsers = append(sessionUsers, User(u))
|
sessionUsers = append(sessionUsers, entities.User(u))
|
||||||
}
|
}
|
||||||
|
|
||||||
currentProject := currentSession.Project
|
currentProject := currentSession.Project
|
||||||
currentDefaultProcessLanguage := Language(currentProject.Settings.DefaultProcessLanguage)
|
currentDefaultProcessLanguage := entities.Language(currentProject.Settings.DefaultProcessLanguage)
|
||||||
currentDefaultTranslateTargetLanguage := Language(currentProject.Settings.DefaultTranslateTargetLanguage)
|
currentDefaultTranslateTargetLanguage := entities.Language(currentProject.Settings.DefaultTranslateTargetLanguage)
|
||||||
project := Project{
|
project := entities.Project{
|
||||||
Id: currentProject.Id,
|
Id: currentProject.Id,
|
||||||
Name: currentProject.Name,
|
Name: currentProject.Name,
|
||||||
OrganizationId: currentProject.OrganizationId,
|
OrganizationId: currentProject.OrganizationId,
|
||||||
Settings: ProjectSettings{
|
Settings: entities.ProjectSettings{
|
||||||
DefaultProcessLanguage: currentDefaultProcessLanguage,
|
DefaultProcessLanguage: currentDefaultProcessLanguage,
|
||||||
DefaultTranslateTargetLanguage: currentDefaultTranslateTargetLanguage,
|
DefaultTranslateTargetLanguage: currentDefaultTranslateTargetLanguage,
|
||||||
IsHosted: currentProject.Settings.IsHosted,
|
IsHosted: currentProject.Settings.IsHosted,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
return Session{
|
return entities.Session{
|
||||||
Project: Project(project),
|
Project: project,
|
||||||
User: User(currentSession.User),
|
User: currentSession.User,
|
||||||
Organization: Organization{
|
Organization: entities.Organization{
|
||||||
Id: currentSession.Organization.Id,
|
Id: currentSession.Organization.Id,
|
||||||
Name: currentSession.Project.Name,
|
Name: currentSession.Project.Name,
|
||||||
LogoPath: currentSession.Organization.LogoPath,
|
LogoPath: currentSession.Organization.LogoPath,
|
||||||
@ -47,23 +47,23 @@ func (c *Channel) GetCurrentSession() Session {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Channel) CreateNewProject(name string) Session {
|
func (c *Channel) CreateNewProject(name string) entities.Session {
|
||||||
currentSession := session.GetInstance()
|
currentSession := session.GetInstance()
|
||||||
|
|
||||||
newProject := session.Project{
|
newProject := entities.Project{
|
||||||
Id: uuid.NewString(),
|
Id: uuid.NewString(),
|
||||||
OrganizationId: currentSession.Project.OrganizationId,
|
OrganizationId: currentSession.Project.OrganizationId,
|
||||||
Name: name,
|
Name: name,
|
||||||
}
|
}
|
||||||
|
|
||||||
successfulProjectWrite := storage.GetDriver().WriteProjectData(storageEntity.Project{
|
successfulProjectWrite := storage.GetDriver().WriteProjectData(entities.Project{
|
||||||
Id: newProject.Id,
|
Id: newProject.Id,
|
||||||
OrganizationId: newProject.OrganizationId,
|
OrganizationId: newProject.OrganizationId,
|
||||||
Name: newProject.Name,
|
Name: newProject.Name,
|
||||||
})
|
})
|
||||||
|
|
||||||
if !successfulProjectWrite {
|
if !successfulProjectWrite {
|
||||||
return Session{}
|
return entities.Session{}
|
||||||
}
|
}
|
||||||
|
|
||||||
currentSession.Project = newProject
|
currentSession.Project = newProject
|
||||||
@ -71,14 +71,14 @@ func (c *Channel) CreateNewProject(name string) Session {
|
|||||||
return c.GetCurrentSession()
|
return c.GetCurrentSession()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Channel) GetCurrentUser() User {
|
func (c *Channel) GetCurrentUser() entities.User {
|
||||||
return User(session.GetInstance().User)
|
return session.GetInstance().User
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Channel) RequestUpdateCurrentUser(updatedUserRequest User) User {
|
func (c *Channel) RequestUpdateCurrentUser(updatedUserRequest entities.User) entities.User {
|
||||||
sessionInstance := session.GetInstance()
|
sessionInstance := session.GetInstance()
|
||||||
|
|
||||||
sessionUser := session.User(sessionInstance.User)
|
sessionUser := entities.User(sessionInstance.User)
|
||||||
|
|
||||||
if sessionUser.LocalId == "" {
|
if sessionUser.LocalId == "" {
|
||||||
sessionUser.LocalId = uuid.NewString()
|
sessionUser.LocalId = uuid.NewString()
|
||||||
@ -95,14 +95,14 @@ func (c *Channel) RequestUpdateCurrentUser(updatedUserRequest User) User {
|
|||||||
|
|
||||||
sessionUser.AvatarPath = updatedUserRequest.AvatarPath
|
sessionUser.AvatarPath = updatedUserRequest.AvatarPath
|
||||||
|
|
||||||
successfulUserWrite := storage.GetDriver().WriteUserData(storageEntity.User(sessionUser))
|
successfulUserWrite := storage.GetDriver().WriteUserData(sessionUser)
|
||||||
if !successfulUserWrite {
|
if !successfulUserWrite {
|
||||||
return User{}
|
return entities.User{}
|
||||||
}
|
}
|
||||||
|
|
||||||
sessionInstance.UpdateCurrentUser(sessionUser)
|
sessionInstance.UpdateCurrentUser(sessionUser)
|
||||||
|
|
||||||
return User(sessionInstance.User)
|
return sessionInstance.User
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Channel) RequestChooseUserAvatar() string {
|
func (c *Channel) RequestChooseUserAvatar() string {
|
||||||
@ -124,43 +124,14 @@ func (c *Channel) RequestChooseUserAvatar() string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Channel) GetAllLocalProjects() []Project {
|
func (c *Channel) GetAllLocalProjects() []entities.Project {
|
||||||
readLocalProjects := storage.GetDriver().ReadAllProjects()
|
readLocalProjects := storage.GetDriver().ReadAllProjects()
|
||||||
response := make([]Project, 0)
|
return readLocalProjects
|
||||||
|
|
||||||
for _, p := range readLocalProjects {
|
|
||||||
response = append(response, Project{
|
|
||||||
Id: p.Id,
|
|
||||||
OrganizationId: p.OrganizationId,
|
|
||||||
Name: p.Name,
|
|
||||||
Settings: ProjectSettings{
|
|
||||||
DefaultProcessLanguage: Language(p.Settings.DefaultProcessLanguage),
|
|
||||||
DefaultTranslateTargetLanguage: Language(p.Settings.DefaultTranslateTargetLanguage),
|
|
||||||
IsHosted: p.Settings.IsHosted,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
return response
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Channel) GetProjectByName(projectName string) Project {
|
func (c *Channel) GetProjectByName(projectName string) entities.Project {
|
||||||
foundProject := storage.GetDriver().ReadProjectDataByName(projectName)
|
foundProject := storage.GetDriver().ReadProjectDataByName(projectName)
|
||||||
|
return foundProject
|
||||||
if foundProject.Id == "" {
|
|
||||||
return Project{}
|
|
||||||
}
|
|
||||||
|
|
||||||
return Project{
|
|
||||||
Id: foundProject.Id,
|
|
||||||
Name: foundProject.Name,
|
|
||||||
OrganizationId: foundProject.OrganizationId,
|
|
||||||
Settings: ProjectSettings{
|
|
||||||
DefaultProcessLanguage: Language(foundProject.Settings.DefaultProcessLanguage),
|
|
||||||
DefaultTranslateTargetLanguage: Language(foundProject.Settings.DefaultTranslateTargetLanguage),
|
|
||||||
IsHosted: foundProject.Settings.IsHosted,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Channel) RequestChangeSessionProjectByName(projectName string) bool {
|
func (c *Channel) RequestChangeSessionProjectByName(projectName string) bool {
|
||||||
@ -171,139 +142,57 @@ func (c *Channel) RequestChangeSessionProjectByName(projectName string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
session.GetInstance().Project = session.Project{
|
session.GetInstance().Project = foundProject
|
||||||
Id: foundProject.Id,
|
|
||||||
Name: foundProject.Name,
|
|
||||||
OrganizationId: foundProject.OrganizationId,
|
|
||||||
Settings: session.ProjectSettings{
|
|
||||||
DefaultProcessLanguage: consts.Language(foundProject.Settings.DefaultProcessLanguage),
|
|
||||||
DefaultTranslateTargetLanguage: consts.Language(foundProject.Settings.DefaultTranslateTargetLanguage),
|
|
||||||
IsHosted: foundProject.Settings.IsHosted,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
localDocumentCollection := storageDriver.ReadDocumentCollection(projectName)
|
localDocumentCollection := storageDriver.ReadDocumentCollection(projectName)
|
||||||
newDocuments := make([]document.Entity, 0)
|
documentCount := len(localDocumentCollection.Documents)
|
||||||
for _, d := range localDocumentCollection.Documents {
|
readableDocuments := make([]document.Entity, documentCount)
|
||||||
newAreas := make([]document.Area, 0)
|
for i := 0; i < documentCount; i++ {
|
||||||
for _, a := range d.Areas {
|
readableDocuments[i] = document.Entity(localDocumentCollection.Documents[i])
|
||||||
newAreas = append(newAreas, document.Area{
|
|
||||||
Id: a.Id,
|
|
||||||
Name: a.Name,
|
|
||||||
StartX: a.StartX,
|
|
||||||
StartY: a.StartY,
|
|
||||||
EndX: a.EndX,
|
|
||||||
EndY: a.EndY,
|
|
||||||
Language: consts.Language(a.Language),
|
|
||||||
Order: a.Order,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
newDocuments = append(newDocuments, document.Entity{
|
|
||||||
Id: d.Id,
|
|
||||||
GroupId: d.GroupId,
|
|
||||||
Name: d.Name,
|
|
||||||
Path: d.Path,
|
|
||||||
ProjectId: d.ProjectId,
|
|
||||||
Areas: newAreas,
|
|
||||||
DefaultLanguage: consts.Language(d.DefaultLanguage),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
newDocumentColllection := document.DocumentCollection{
|
document.SetDocumentCollection(document.DocumentCollection{
|
||||||
Documents: newDocuments,
|
Documents: readableDocuments,
|
||||||
ProjectId: foundProject.Id,
|
ProjectId: foundProject.Id,
|
||||||
}
|
})
|
||||||
document.SetDocumentCollection(newDocumentColllection)
|
|
||||||
|
|
||||||
localGroupsCollection := storageDriver.ReadGroupCollection(projectName)
|
localGroupsCollection := storageDriver.ReadGroupCollection(projectName)
|
||||||
newGroups := make([]document.Group, 0)
|
groupCount := len(localGroupsCollection.Groups)
|
||||||
for _, g := range localGroupsCollection.Groups {
|
readableGroups := make([]entities.Group, groupCount)
|
||||||
newGroups = append(newGroups, document.Group(g))
|
for i := 0; i < groupCount; i++ {
|
||||||
|
readableGroups[i] = entities.Group(localGroupsCollection.Groups[i])
|
||||||
}
|
}
|
||||||
newGroupCollection := document.GroupCollection{
|
document.SetGroupCollection(document.GroupCollection{
|
||||||
Id: localGroupsCollection.Id,
|
Id: localGroupsCollection.Id,
|
||||||
ProjectId: localGroupsCollection.ProjectId,
|
ProjectId: localGroupsCollection.ProjectId,
|
||||||
Groups: newGroups,
|
Groups: readableGroups,
|
||||||
}
|
})
|
||||||
document.SetGroupCollection(newGroupCollection)
|
|
||||||
|
|
||||||
// Processed Texts
|
// Processed Texts
|
||||||
|
|
||||||
localProcessedAreaCollection := storageDriver.ReadProcessedTextCollection(projectName)
|
localProcessedAreaCollection := storageDriver.ReadProcessedTextCollection(projectName)
|
||||||
newAreas := make([]document.ProcessedArea, 0)
|
areaCount := len(localProcessedAreaCollection.Areas)
|
||||||
for _, a := range localProcessedAreaCollection.Areas {
|
readableAreas := make([]entities.ProcessedArea, areaCount)
|
||||||
linesOfArea := make([]document.ProcessedLine, 0)
|
for i := 0; i < areaCount; i++ {
|
||||||
for _, l := range a.Lines {
|
readableAreas[i] = entities.ProcessedArea(localProcessedAreaCollection.Areas[i])
|
||||||
wordsOfLine := make([]document.ProcessedWord, 0)
|
|
||||||
|
|
||||||
for _, w := range l.Words {
|
|
||||||
symbolsOfWord := make([]document.ProcessedSymbol, 0)
|
|
||||||
|
|
||||||
for _, s := range w.Symbols {
|
|
||||||
symbolsOfWord = append(symbolsOfWord, document.ProcessedSymbol{
|
|
||||||
Text: s.Text,
|
|
||||||
Confidence: s.Confidence,
|
|
||||||
BoundingBox: document.ProcessedBoundingBox(s.BoundingBox),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
wordsOfLine = append(wordsOfLine, document.ProcessedWord{
|
|
||||||
FullText: w.FullText,
|
|
||||||
Confidence: w.Confidence,
|
|
||||||
Direction: w.Direction,
|
|
||||||
BoundingBox: document.ProcessedBoundingBox(w.BoundingBox),
|
|
||||||
Symbols: symbolsOfWord,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
linesOfArea = append(linesOfArea, document.ProcessedLine{
|
|
||||||
FullText: l.FullText,
|
|
||||||
Words: wordsOfLine,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
newAreas = append(newAreas, document.ProcessedArea{
|
|
||||||
Id: a.Id,
|
|
||||||
DocumentId: a.DocumentId,
|
|
||||||
FullText: a.FullText,
|
|
||||||
Order: a.Order,
|
|
||||||
Lines: linesOfArea,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
document.SetProcessedAreaCollection(document.ProcessedAreaCollection{
|
document.SetProcessedAreaCollection(document.ProcessedAreaCollection{
|
||||||
Areas: newAreas,
|
Areas: readableAreas,
|
||||||
})
|
})
|
||||||
|
|
||||||
// UserProcessedMarkdown
|
// UserProcessedMarkdown
|
||||||
|
|
||||||
localUserProcessedMarkdown := storageDriver.ReadProcessedUserMarkdownCollection(projectName)
|
localUserProcessedMarkdown := storageDriver.ReadProcessedUserMarkdownCollection(projectName)
|
||||||
|
userProcessedMarkdownCount := len(localUserProcessedMarkdown.Values)
|
||||||
newUserProcessedMarkdown := make([]document.UserMarkdown, 0)
|
readableUserProcessedMarkdown := make([]entities.UserMarkdown, userProcessedMarkdownCount)
|
||||||
for _, v := range localUserProcessedMarkdown.Values {
|
for i := 0; i < userProcessedMarkdownCount; i++ {
|
||||||
newUserProcessedMarkdown = append(newUserProcessedMarkdown, document.UserMarkdown{
|
readableUserProcessedMarkdown[i] = entities.UserMarkdown(localUserProcessedMarkdown.Values[i])
|
||||||
Id: v.Id,
|
|
||||||
DocumentId: v.DocumentId,
|
|
||||||
Value: v.Value,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
document.SetUserMarkdownCollection(document.UserMarkdownCollection{
|
document.SetUserMarkdownCollection(document.UserMarkdownCollection{
|
||||||
Values: newUserProcessedMarkdown,
|
Values: readableUserProcessedMarkdown,
|
||||||
})
|
})
|
||||||
|
|
||||||
// End UserProcessedMarkdown
|
|
||||||
|
|
||||||
return session.GetInstance().Project.Id == foundProject.Id
|
return session.GetInstance().Project.Id == foundProject.Id
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Channel) GetSuppportedLanguages() []Language {
|
func (c *Channel) GetSuppportedLanguages() []entities.Language {
|
||||||
supportedLanguages := consts.GetSuppportedLanguages()
|
supportedLanguages := consts.GetSuppportedLanguages()
|
||||||
|
return supportedLanguages
|
||||||
var response []Language
|
|
||||||
|
|
||||||
for _, l := range supportedLanguages {
|
|
||||||
response = append(response, Language(l))
|
|
||||||
}
|
|
||||||
|
|
||||||
return response
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,20 +2,20 @@ package storage
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
entity "textualize/storage/Entities"
|
"textualize/entities"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (d LocalDriver) WriteDocumentCollection(documentCollection entity.DocumentCollection, projectName string) bool {
|
func (d LocalDriver) WriteDocumentCollection(documentCollection entities.DocumentCollection, projectName string) bool {
|
||||||
jsonData, _ := json.MarshalIndent(documentCollection, "", " ")
|
jsonData, _ := json.MarshalIndent(documentCollection, "", " ")
|
||||||
writeError := WriteDataToAppDir(jsonData, "/projects/"+projectName+"/", "Documents.json")
|
writeError := WriteDataToAppDir(jsonData, "/projects/"+projectName+"/", "Documents.json")
|
||||||
return writeError == nil
|
return writeError == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d LocalDriver) ReadDocumentCollection(projectName string) entity.DocumentCollection {
|
func (d LocalDriver) ReadDocumentCollection(projectName string) entities.DocumentCollection {
|
||||||
documentCollectionData := entity.DocumentCollection{}
|
documentCollectionData := entities.DocumentCollection{}
|
||||||
readError := AssignFileDataToStruct("/projects/"+projectName+"/Documents.json", &documentCollectionData)
|
readError := AssignFileDataToStruct("/projects/"+projectName+"/Documents.json", &documentCollectionData)
|
||||||
if readError != nil {
|
if readError != nil {
|
||||||
return entity.DocumentCollection{}
|
return entities.DocumentCollection{}
|
||||||
}
|
}
|
||||||
|
|
||||||
return documentCollectionData
|
return documentCollectionData
|
||||||
|
|||||||
@ -2,20 +2,20 @@ package storage
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
entity "textualize/storage/Entities"
|
"textualize/entities"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (d LocalDriver) WriteGroupCollection(collection entity.GroupCollection, projectName string) bool {
|
func (d LocalDriver) WriteGroupCollection(collection entities.GroupCollection, projectName string) bool {
|
||||||
jsonData, _ := json.MarshalIndent(collection, "", " ")
|
jsonData, _ := json.MarshalIndent(collection, "", " ")
|
||||||
writeError := WriteDataToAppDir(jsonData, "/projects/"+projectName+"/", "Groups.json")
|
writeError := WriteDataToAppDir(jsonData, "/projects/"+projectName+"/", "Groups.json")
|
||||||
return writeError == nil
|
return writeError == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d LocalDriver) ReadGroupCollection(projectName string) entity.GroupCollection {
|
func (d LocalDriver) ReadGroupCollection(projectName string) entities.GroupCollection {
|
||||||
collectionData := entity.GroupCollection{}
|
collectionData := entities.GroupCollection{}
|
||||||
readError := AssignFileDataToStruct("/projects/"+projectName+"/Groups.json", &collectionData)
|
readError := AssignFileDataToStruct("/projects/"+projectName+"/Groups.json", &collectionData)
|
||||||
if readError != nil {
|
if readError != nil {
|
||||||
return entity.GroupCollection{}
|
return entities.GroupCollection{}
|
||||||
}
|
}
|
||||||
|
|
||||||
return collectionData
|
return collectionData
|
||||||
|
|||||||
@ -2,36 +2,36 @@ package storage
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
entity "textualize/storage/Entities"
|
"textualize/entities"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (d LocalDriver) WriteProcessedTextCollection(collection entity.ProcessedTextCollection, projectName string) bool {
|
func (d LocalDriver) WriteProcessedTextCollection(collection entities.ProcessedTextCollection, projectName string) bool {
|
||||||
jsonData, _ := json.MarshalIndent(collection, "", " ")
|
jsonData, _ := json.MarshalIndent(collection, "", " ")
|
||||||
writeError := WriteDataToAppDir(jsonData, "/projects/"+projectName+"/", "ProcessedTexts.json")
|
writeError := WriteDataToAppDir(jsonData, "/projects/"+projectName+"/", "ProcessedTexts.json")
|
||||||
return writeError == nil
|
return writeError == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d LocalDriver) ReadProcessedTextCollection(projectName string) entity.ProcessedTextCollection {
|
func (d LocalDriver) ReadProcessedTextCollection(projectName string) entities.ProcessedTextCollection {
|
||||||
collectionData := entity.ProcessedTextCollection{}
|
collectionData := entities.ProcessedTextCollection{}
|
||||||
readError := AssignFileDataToStruct("/projects/"+projectName+"/ProcessedTexts.json", &collectionData)
|
readError := AssignFileDataToStruct("/projects/"+projectName+"/ProcessedTexts.json", &collectionData)
|
||||||
if readError != nil {
|
if readError != nil {
|
||||||
return entity.ProcessedTextCollection{}
|
return entities.ProcessedTextCollection{}
|
||||||
}
|
}
|
||||||
|
|
||||||
return collectionData
|
return collectionData
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d LocalDriver) WriteProcessedUserMarkdownCollection(collection entity.ProcessedUserMarkdownCollection, projectName string) bool {
|
func (d LocalDriver) WriteProcessedUserMarkdownCollection(collection entities.ProcessedUserMarkdownCollection, projectName string) bool {
|
||||||
jsonData, _ := json.MarshalIndent(collection, "", " ")
|
jsonData, _ := json.MarshalIndent(collection, "", " ")
|
||||||
writeError := WriteDataToAppDir(jsonData, "/projects/"+projectName+"/", "UserProcessedMarkdown.json")
|
writeError := WriteDataToAppDir(jsonData, "/projects/"+projectName+"/", "UserProcessedMarkdown.json")
|
||||||
return writeError == nil
|
return writeError == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d LocalDriver) ReadProcessedUserMarkdownCollection(projectName string) entity.ProcessedUserMarkdownCollection {
|
func (d LocalDriver) ReadProcessedUserMarkdownCollection(projectName string) entities.ProcessedUserMarkdownCollection {
|
||||||
collectionData := entity.ProcessedUserMarkdownCollection{}
|
collectionData := entities.ProcessedUserMarkdownCollection{}
|
||||||
readError := AssignFileDataToStruct("/projects/"+projectName+"/UserProcessedMarkdown.json", &collectionData)
|
readError := AssignFileDataToStruct("/projects/"+projectName+"/UserProcessedMarkdown.json", &collectionData)
|
||||||
if readError != nil {
|
if readError != nil {
|
||||||
return entity.ProcessedUserMarkdownCollection{}
|
return entities.ProcessedUserMarkdownCollection{}
|
||||||
}
|
}
|
||||||
|
|
||||||
return collectionData
|
return collectionData
|
||||||
|
|||||||
@ -3,27 +3,27 @@ package storage
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"os"
|
"os"
|
||||||
storage "textualize/storage/Entities"
|
"textualize/entities"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (d LocalDriver) WriteProjectData(project storage.Project) bool {
|
func (d LocalDriver) WriteProjectData(project entities.Project) bool {
|
||||||
jsonData, _ := json.MarshalIndent(project, "", " ")
|
jsonData, _ := json.MarshalIndent(project, "", " ")
|
||||||
writeError := WriteDataToAppDir(jsonData, "/projects/"+project.Name+"/", "Project.json")
|
writeError := WriteDataToAppDir(jsonData, "/projects/"+project.Name+"/", "Project.json")
|
||||||
return writeError == nil
|
return writeError == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d LocalDriver) ReadProjectDataByName(projectName string) storage.Project {
|
func (d LocalDriver) ReadProjectDataByName(projectName string) entities.Project {
|
||||||
projectData := storage.Project{}
|
projectData := entities.Project{}
|
||||||
readError := AssignFileDataToStruct("/projects/"+projectName+"/Project.json", &projectData)
|
readError := AssignFileDataToStruct("/projects/"+projectName+"/Project.json", &projectData)
|
||||||
if readError != nil {
|
if readError != nil {
|
||||||
return storage.Project{}
|
return entities.Project{}
|
||||||
}
|
}
|
||||||
|
|
||||||
return projectData
|
return projectData
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d LocalDriver) ReadAllProjects() []storage.Project {
|
func (d LocalDriver) ReadAllProjects() []entities.Project {
|
||||||
localProjects := make([]storage.Project, 0)
|
localProjects := make([]entities.Project, 0)
|
||||||
|
|
||||||
subdirectory := "/projects/"
|
subdirectory := "/projects/"
|
||||||
isLocalStorageDirectoryCreated := createLocalStorageSubDirIfNeeded(subdirectory)
|
isLocalStorageDirectoryCreated := createLocalStorageSubDirIfNeeded(subdirectory)
|
||||||
|
|||||||
@ -2,20 +2,20 @@ package storage
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
storage "textualize/storage/Entities"
|
"textualize/entities"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (d LocalDriver) WriteUserData(user storage.User) bool {
|
func (d LocalDriver) WriteUserData(user entities.User) bool {
|
||||||
jsonData, _ := json.MarshalIndent(user, "", " ")
|
jsonData, _ := json.MarshalIndent(user, "", " ")
|
||||||
writeError := WriteDataToAppDir(jsonData, "/", "User.json")
|
writeError := WriteDataToAppDir(jsonData, "/", "User.json")
|
||||||
return writeError == nil
|
return writeError == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d LocalDriver) ReadUserData() storage.User {
|
func (d LocalDriver) ReadUserData() entities.User {
|
||||||
userData := storage.User{}
|
userData := entities.User{}
|
||||||
readError := AssignFileDataToStruct("/User.json", &userData)
|
readError := AssignFileDataToStruct("/User.json", &userData)
|
||||||
if readError != nil {
|
if readError != nil {
|
||||||
return storage.User{}
|
return entities.User{}
|
||||||
}
|
}
|
||||||
|
|
||||||
return userData
|
return userData
|
||||||
|
|||||||
@ -1,24 +1,24 @@
|
|||||||
package storage
|
package storage
|
||||||
|
|
||||||
import (
|
import (
|
||||||
entity "textualize/storage/Entities"
|
"textualize/entities"
|
||||||
local "textualize/storage/Local"
|
local "textualize/storage/Local"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Driver interface {
|
type Driver interface {
|
||||||
WriteUserData(entity.User) bool
|
WriteUserData(entities.User) bool
|
||||||
ReadUserData() entity.User
|
ReadUserData() entities.User
|
||||||
WriteProjectData(entity.Project) bool
|
WriteProjectData(entities.Project) bool
|
||||||
ReadProjectDataByName(string) entity.Project
|
ReadProjectDataByName(string) entities.Project
|
||||||
ReadAllProjects() []entity.Project
|
ReadAllProjects() []entities.Project
|
||||||
WriteDocumentCollection(entity.DocumentCollection, string) bool
|
WriteDocumentCollection(entities.DocumentCollection, string) bool
|
||||||
ReadDocumentCollection(string) entity.DocumentCollection
|
ReadDocumentCollection(string) entities.DocumentCollection
|
||||||
WriteGroupCollection(entity.GroupCollection, string) bool
|
WriteGroupCollection(entities.GroupCollection, string) bool
|
||||||
ReadGroupCollection(string) entity.GroupCollection
|
ReadGroupCollection(string) entities.GroupCollection
|
||||||
WriteProcessedTextCollection(entity.ProcessedTextCollection, string) bool
|
WriteProcessedTextCollection(entities.ProcessedTextCollection, string) bool
|
||||||
ReadProcessedTextCollection(string) entity.ProcessedTextCollection
|
ReadProcessedTextCollection(string) entities.ProcessedTextCollection
|
||||||
WriteProcessedUserMarkdownCollection(entity.ProcessedUserMarkdownCollection, string) bool
|
WriteProcessedUserMarkdownCollection(entities.ProcessedUserMarkdownCollection, string) bool
|
||||||
ReadProcessedUserMarkdownCollection(string) entity.ProcessedUserMarkdownCollection
|
ReadProcessedUserMarkdownCollection(string) entities.ProcessedUserMarkdownCollection
|
||||||
}
|
}
|
||||||
|
|
||||||
var driverInstance Driver
|
var driverInstance Driver
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 70 KiB |
Loading…
x
Reference in New Issue
Block a user