Compare commits
4 Commits
main
...
generalize
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7335b636f4 | ||
|
|
8b55241ee4 | ||
|
|
c01ba92021 | ||
|
|
f9cc43a0c5 |
@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
document "textualize/core/Document"
|
||||
session "textualize/core/Session"
|
||||
"textualize/entities"
|
||||
storage "textualize/storage"
|
||||
)
|
||||
|
||||
@ -26,10 +27,10 @@ func (a *App) Startup(ctx context.Context) {
|
||||
a.Context = ctx
|
||||
localUserData := storage.GetDriver().ReadUserData()
|
||||
session.InitializeModule(session.Session{
|
||||
User: session.User(localUserData),
|
||||
User: entities.User(localUserData),
|
||||
})
|
||||
|
||||
document.InitizeModule()
|
||||
document.InitializeModule()
|
||||
|
||||
fmt.Println(localUserData)
|
||||
}
|
||||
|
||||
@ -1,13 +1,9 @@
|
||||
package consts
|
||||
|
||||
type Language struct {
|
||||
DisplayName string
|
||||
ProcessCode string
|
||||
TranslateCode string
|
||||
}
|
||||
import "textualize/entities"
|
||||
|
||||
func GetSuppportedLanguages() []Language {
|
||||
return []Language{
|
||||
func GetSuppportedLanguages() []entities.Language {
|
||||
return []entities.Language{
|
||||
{
|
||||
DisplayName: "English",
|
||||
ProcessCode: "eng",
|
||||
|
||||
@ -1,36 +1,19 @@
|
||||
package document
|
||||
|
||||
import (
|
||||
consts "textualize/core/Consts"
|
||||
"textualize/entities"
|
||||
)
|
||||
|
||||
type Entity struct {
|
||||
Id string
|
||||
GroupId string
|
||||
Name string
|
||||
Path string
|
||||
ProjectId string
|
||||
Areas []Area
|
||||
DefaultLanguage consts.Language
|
||||
}
|
||||
type Entity entities.Document
|
||||
|
||||
type Area struct {
|
||||
Id string
|
||||
Name string
|
||||
StartX int
|
||||
StartY int
|
||||
EndX int
|
||||
EndY int
|
||||
Language consts.Language
|
||||
Order int
|
||||
}
|
||||
type Area entities.Area
|
||||
|
||||
func (e *Entity) AddArea(a Area) {
|
||||
func (e *Entity) AddArea(a entities.Area) {
|
||||
e.Areas = append(e.Areas, a)
|
||||
}
|
||||
|
||||
func (e *Entity) GetAreaById(areaId string) *Area {
|
||||
var foundArea *Area
|
||||
func (e *Entity) GetAreaById(areaId string) *entities.Area {
|
||||
var foundArea *entities.Area
|
||||
|
||||
for index, a := range e.Areas {
|
||||
if a.Id == areaId {
|
||||
|
||||
@ -1,18 +1,10 @@
|
||||
package document
|
||||
|
||||
type Group struct {
|
||||
Id string
|
||||
ParentId string
|
||||
ProjectId string
|
||||
Name string
|
||||
Order int
|
||||
}
|
||||
import "textualize/entities"
|
||||
|
||||
type GroupCollection struct {
|
||||
Id string
|
||||
Groups []Group
|
||||
ProjectId string
|
||||
}
|
||||
type Group entities.Group
|
||||
|
||||
type GroupCollection entities.GroupCollection
|
||||
|
||||
var groupCollectionInstance *GroupCollection
|
||||
|
||||
@ -29,12 +21,12 @@ func SetGroupCollection(collection GroupCollection) *GroupCollection {
|
||||
return groupCollectionInstance
|
||||
}
|
||||
|
||||
func (collection *GroupCollection) AddDocumentGroup(group Group) {
|
||||
func (collection *GroupCollection) AddDocumentGroup(group entities.Group) {
|
||||
collection.Groups = append(collection.Groups, group)
|
||||
}
|
||||
|
||||
func (collection *GroupCollection) GetGroupById(groupId string) *Group {
|
||||
var foundGroup *Group
|
||||
func (collection *GroupCollection) GetGroupById(groupId string) *entities.Group {
|
||||
var foundGroup *entities.Group
|
||||
|
||||
for index, g := range collection.Groups {
|
||||
if g.Id == groupId {
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
package document
|
||||
|
||||
func InitizeModule() {
|
||||
import "textualize/entities"
|
||||
|
||||
func InitializeModule() {
|
||||
GetDocumentCollection()
|
||||
GetGroupCollection()
|
||||
}
|
||||
@ -9,7 +11,7 @@ func createTestData() {
|
||||
documentCollection := GetDocumentCollection()
|
||||
documentGroupCollection := GetGroupCollection()
|
||||
|
||||
documentGroupCollection.AddDocumentGroup(Group{
|
||||
documentGroupCollection.AddDocumentGroup(entities.Group{
|
||||
Id: "XYZ",
|
||||
Name: "Test Group One",
|
||||
})
|
||||
|
||||
@ -1,42 +1,9 @@
|
||||
package document
|
||||
|
||||
type ProcessedBoundingBox struct {
|
||||
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
|
||||
}
|
||||
import "textualize/entities"
|
||||
|
||||
type ProcessedAreaCollection struct {
|
||||
Areas []ProcessedArea
|
||||
Areas []entities.ProcessedArea
|
||||
}
|
||||
|
||||
var processedAreaCollectionInstnace *ProcessedAreaCollection
|
||||
@ -52,12 +19,12 @@ func SetProcessedAreaCollection(collection ProcessedAreaCollection) {
|
||||
processedAreaCollectionInstnace = &collection
|
||||
}
|
||||
|
||||
func (collection *ProcessedAreaCollection) AddProcessedArea(area ProcessedArea) {
|
||||
func (collection *ProcessedAreaCollection) AddProcessedArea(area entities.ProcessedArea) {
|
||||
collection.Areas = append(collection.Areas, area)
|
||||
}
|
||||
|
||||
func (collection *ProcessedAreaCollection) GetAreasByDocumentId(id string) []*ProcessedArea {
|
||||
var foundAreas []*ProcessedArea
|
||||
func (collection *ProcessedAreaCollection) GetAreasByDocumentId(id string) []*entities.ProcessedArea {
|
||||
var foundAreas []*entities.ProcessedArea
|
||||
|
||||
for index, a := range collection.Areas {
|
||||
if a.DocumentId == id {
|
||||
@ -68,8 +35,8 @@ func (collection *ProcessedAreaCollection) GetAreasByDocumentId(id string) []*Pr
|
||||
return foundAreas
|
||||
}
|
||||
|
||||
func (collection *ProcessedAreaCollection) GetAreaById(areaId string) *ProcessedArea {
|
||||
var foundArea *ProcessedArea
|
||||
func (collection *ProcessedAreaCollection) GetAreaById(areaId string) *entities.ProcessedArea {
|
||||
var foundArea *entities.ProcessedArea
|
||||
|
||||
for index, a := range collection.Areas {
|
||||
if a.Id == areaId {
|
||||
|
||||
@ -1,13 +1,9 @@
|
||||
package document
|
||||
|
||||
type UserMarkdown struct {
|
||||
Id string
|
||||
DocumentId string
|
||||
Value string
|
||||
}
|
||||
import "textualize/entities"
|
||||
|
||||
type UserMarkdownCollection struct {
|
||||
Values []UserMarkdown
|
||||
Values []entities.UserMarkdown
|
||||
}
|
||||
|
||||
var userMarkdownCollection *UserMarkdownCollection
|
||||
@ -24,8 +20,8 @@ func SetUserMarkdownCollection(collection UserMarkdownCollection) {
|
||||
userMarkdownCollection = &collection
|
||||
}
|
||||
|
||||
func (collection *UserMarkdownCollection) GetUserMarkdownByDocumentId(documentId string) *UserMarkdown {
|
||||
var foundUserMarkdown *UserMarkdown
|
||||
func (collection *UserMarkdownCollection) GetUserMarkdownByDocumentId(documentId string) *entities.UserMarkdown {
|
||||
var foundUserMarkdown *entities.UserMarkdown
|
||||
|
||||
for index, m := range collection.Values {
|
||||
if m.DocumentId == documentId {
|
||||
@ -37,12 +33,12 @@ func (collection *UserMarkdownCollection) GetUserMarkdownByDocumentId(documentId
|
||||
return foundUserMarkdown
|
||||
}
|
||||
|
||||
func (collection *UserMarkdownCollection) AddUserMarkdown(userMarkdown UserMarkdown) UserMarkdown {
|
||||
func (collection *UserMarkdownCollection) AddUserMarkdown(userMarkdown entities.UserMarkdown) entities.UserMarkdown {
|
||||
collection.Values = append(collection.Values, userMarkdown)
|
||||
return userMarkdown
|
||||
}
|
||||
|
||||
func (collection *UserMarkdownCollection) UpdateUserMarkdown(userMarkdown UserMarkdown) UserMarkdown {
|
||||
func (collection *UserMarkdownCollection) UpdateUserMarkdown(userMarkdown entities.UserMarkdown) entities.UserMarkdown {
|
||||
currentUserMarkdown := collection.GetUserMarkdownByDocumentId(userMarkdown.DocumentId)
|
||||
|
||||
if currentUserMarkdown != nil {
|
||||
|
||||
@ -1,8 +1,5 @@
|
||||
package session
|
||||
|
||||
type Organization struct {
|
||||
Id string
|
||||
Name string
|
||||
LogoPath string
|
||||
Users []User
|
||||
}
|
||||
import "textualize/entities"
|
||||
|
||||
type Organization entities.Organization
|
||||
|
||||
@ -1,18 +1,9 @@
|
||||
package session
|
||||
|
||||
import (
|
||||
consts "textualize/core/Consts"
|
||||
"textualize/entities"
|
||||
)
|
||||
|
||||
type Project struct {
|
||||
Id string
|
||||
OrganizationId string
|
||||
Name string
|
||||
Settings ProjectSettings
|
||||
}
|
||||
type Project entities.Project
|
||||
|
||||
type ProjectSettings struct {
|
||||
DefaultProcessLanguage consts.Language
|
||||
DefaultTranslateTargetLanguage consts.Language
|
||||
IsHosted bool
|
||||
}
|
||||
type ProjectSettings entities.ProjectSettings
|
||||
|
||||
@ -1,10 +1,8 @@
|
||||
package session
|
||||
|
||||
type Session struct {
|
||||
Project Project
|
||||
Organization Organization
|
||||
User User
|
||||
}
|
||||
import "textualize/entities"
|
||||
|
||||
type Session entities.Session
|
||||
|
||||
var sessionInstance *Session
|
||||
|
||||
@ -22,7 +20,7 @@ func InitializeModule(newSession Session) *Session {
|
||||
return sessionInstance
|
||||
}
|
||||
|
||||
func (s *Session) UpdateCurrentUser(updatedUser User) User {
|
||||
s.User = User(updatedUser)
|
||||
func (s *Session) UpdateCurrentUser(updatedUser entities.User) entities.User {
|
||||
s.User = entities.User(updatedUser)
|
||||
return s.User
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package storage
|
||||
package entities
|
||||
|
||||
type DocumentCollection struct {
|
||||
Documents []Document `json:"documents"`
|
||||
@ -1,4 +1,4 @@
|
||||
package storage
|
||||
package entities
|
||||
|
||||
type Group struct {
|
||||
Id string `json:"id"`
|
||||
@ -1,4 +1,4 @@
|
||||
package storage
|
||||
package entities
|
||||
|
||||
type Language struct {
|
||||
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 {
|
||||
X0 int32 `json:"x0"`
|
||||
@ -1,4 +1,4 @@
|
||||
package storage
|
||||
package entities
|
||||
|
||||
type Project struct {
|
||||
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 {
|
||||
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 { ipc } from '../../wailsjs/wailsjs/go/models'
|
||||
import { entities } from '../../wailsjs/wailsjs/go/models'
|
||||
import classNames from '../../utils/classNames'
|
||||
|
||||
type Props = {
|
||||
areas: ipc.Area[]
|
||||
processedArea?: ipc.ProcessedArea
|
||||
areas: entities.Area[]
|
||||
processedArea?: entities.ProcessedArea
|
||||
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) => {
|
||||
|
||||
@ -1,15 +1,15 @@
|
||||
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 onEnterHandler from '../../utils/onEnterHandler'
|
||||
import { useProject } from '../../context/Project/provider'
|
||||
|
||||
type Props = {
|
||||
zoomLevel: number
|
||||
processedArea?: ipc.ProcessedArea
|
||||
wordToEdit?: ipc.ProcessedWord
|
||||
setWordToEdit: (props?: { word: ipc.ProcessedWord, areaId: string }) => void
|
||||
setHoveredProcessedArea: (area?: ipc.ProcessedArea) => void
|
||||
processedArea?: entities.ProcessedArea
|
||||
wordToEdit?: entities.ProcessedWord
|
||||
setWordToEdit: (props?: { word: entities.ProcessedWord, areaId: string }) => void
|
||||
setHoveredProcessedArea: (area?: entities.ProcessedArea) => void
|
||||
}
|
||||
|
||||
const EditProcessedWord = ({ setWordToEdit, zoomLevel, wordToEdit, processedArea, setHoveredProcessedArea }: Props) => {
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
import React, { WheelEvent, useEffect, useRef, useState } from 'react'
|
||||
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 processImageArea from '../../useCases/processImageArea'
|
||||
import AreaTextPreview from './AreaTextPreview'
|
||||
@ -30,8 +30,8 @@ const UiCanvas = (props: Props) => {
|
||||
} = useProject()
|
||||
const canvas = useRef<HTMLCanvasElement>(null)
|
||||
const [hoverOverAreaId, setHoverOverAreaId] = useState('')
|
||||
const [wordToEdit, setWordToEdit] = useState<{ word: ipc.ProcessedWord, areaId: string } | undefined>()
|
||||
const [hoveredProcessedArea, setHoveredProcessedArea] = useState<ipc.ProcessedArea | undefined>()
|
||||
const [wordToEdit, setWordToEdit] = useState<{ word: entities.ProcessedWord, areaId: string } | undefined>()
|
||||
const [hoveredProcessedArea, setHoveredProcessedArea] = useState<entities.ProcessedArea | undefined>()
|
||||
|
||||
const areas = getSelectedDocument()?.areas || []
|
||||
const { width, height, zoomDetails, setZoomLevel } = props
|
||||
|
||||
@ -1,28 +1,6 @@
|
||||
import isInBounds from '../../utils/isInBounds'
|
||||
import { ipc } from '../../wailsjs/wailsjs/go/models'
|
||||
|
||||
|
||||
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
|
||||
import { entities } from '../../wailsjs/wailsjs/go/models'
|
||||
import { AddAreaToStoreCallback, HoverOverAreaCallback, MouseCoordinates, RectangleCoordinates, SetZoomCallback, ZoomDetails } from './types'
|
||||
|
||||
/**
|
||||
* @param uiCanvas
|
||||
@ -75,7 +53,7 @@ const createUiCanvasInteractions = (uiCanvas: HTMLCanvasElement) => {
|
||||
if (shouldAttemptToZoomIn) 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
|
||||
|
||||
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 { useProject } from '../../context/Project/provider'
|
||||
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 ProjectListModal from './ProjectListModal'
|
||||
|
||||
@ -17,7 +17,7 @@ const MainProject = () => {
|
||||
const [isProjectListModal, setIsProjectListModal] = useState(false)
|
||||
const [canPopoverBeOpen, setCanPopoverBeOpen] = useState(true)
|
||||
|
||||
const [avalibleProjects, setAvalibleProjects] = useState<ipc.Project[]>([])
|
||||
const [avalibleProjects, setAvalibleProjects] = useState<entities.Project[]>([])
|
||||
const { createNewProject, requestSelectProjectByName } = useProject()
|
||||
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) => {
|
||||
|
||||
return (
|
||||
|
||||
@ -5,17 +5,17 @@ import { useEffect, useState } from 'react'
|
||||
import { useProject } from '../../context/Project/provider'
|
||||
import classNames from '../../utils/classNames'
|
||||
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 forDocumentType = { shouldUpdateDocument?: true, shouldUpdateArea?: never }
|
||||
type Props = (forAreaType | forDocumentType) & { defaultLanguage?: ipc.Language }
|
||||
type Props = (forAreaType | forDocumentType) & { defaultLanguage?: entities.Language }
|
||||
|
||||
const LanguageSelect = (props?: Props) => {
|
||||
const { requestUpdateDocument, getSelectedDocument } = useProject()
|
||||
const [languages, setLanguages] = useState<ipc.Language[]>([])
|
||||
const [languages, setLanguages] = useState<entities.Language[]>([])
|
||||
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 === ''
|
||||
@ -47,7 +47,7 @@ const LanguageSelect = (props?: Props) => {
|
||||
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"
|
||||
onChange={(event) => setQuery(event.target.value)}
|
||||
displayValue={(language: ipc.Language) => language?.displayName}
|
||||
displayValue={(language: entities.Language) => language?.displayName}
|
||||
placeholder='Document Language'
|
||||
/>
|
||||
<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 (
|
||||
<li className='p-0 m-0' key={props.document.id}>
|
||||
{!props.document.areas.length
|
||||
{!props.document.areas?.length
|
||||
?
|
||||
<div
|
||||
onClick={() => onDocumentClickHandler(props.document.id)}
|
||||
@ -149,52 +149,6 @@ const DocumentLineItem = (props: { document: SidebarDocument, groupId: string, i
|
||||
<ul>
|
||||
{props.document.areas.map((a, index) => (
|
||||
<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>
|
||||
</details>
|
||||
|
||||
@ -1,17 +1,14 @@
|
||||
'use client'
|
||||
|
||||
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 classNames from '../../../utils/classNames'
|
||||
import onEnterHandler from '../../../utils/onEnterHandler'
|
||||
import AddGroupInput from './AddGroupInput'
|
||||
import DocumentLineItem from './DocumentLineItem'
|
||||
import { useSidebar } from './provider'
|
||||
import { SidebarGroup } from './types'
|
||||
|
||||
|
||||
|
||||
const GroupLineItem = (props: { group: SidebarGroup, dragOverGroupId?: string }) => {
|
||||
const {
|
||||
requestAddDocument,
|
||||
@ -58,10 +55,6 @@ const GroupLineItem = (props: { group: SidebarGroup, dragOverGroupId?: string })
|
||||
setDragOverGroupId(groupId)
|
||||
}
|
||||
|
||||
const onGroupDragStart = (groupId: string) => {
|
||||
setSelectedGroupId(groupId)
|
||||
}
|
||||
|
||||
const onGroupDropEnd = (groupId: string) => {
|
||||
if (!groupId || groupId == dragOverGroupId) return
|
||||
|
||||
@ -136,140 +129,6 @@ const GroupLineItem = (props: { group: SidebarGroup, dragOverGroupId?: string })
|
||||
<ul>
|
||||
{props.group.documents.map((d, index) => (
|
||||
<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)}
|
||||
|
||||
@ -16,6 +16,10 @@ const makeDefaultSidebar = (): SidebarContextType => ({
|
||||
setIsAddNewGroupInputShowing: (_: boolean) => {},
|
||||
isEditAreaNameInputShowing: false,
|
||||
setIsEditAreaNameInputShowing: (_: boolean) => {},
|
||||
dragOverGroupId: '',
|
||||
setDragOverGroupId: (_: string) => {},
|
||||
dragOverAreaId: '',
|
||||
setDragOverAreaId: (_: string) => {},
|
||||
})
|
||||
|
||||
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'
|
||||
|
||||
const getNavigationProps = (documents: ipc.Document[], groups: ipc.Group[]) : SidebarGroup[] => {
|
||||
const getNavigationProps = (documents: entities.Document[], groups: entities.Group[]) : SidebarGroup[] => {
|
||||
const groupsWithDocuments = groups.map(g => {
|
||||
const childrenDocuments = documents
|
||||
.filter(d => d.groupId === g.id)
|
||||
.map(d => ({
|
||||
id: d.id,
|
||||
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 {
|
||||
@ -23,7 +23,7 @@ const getNavigationProps = (documents: ipc.Document[], groups: ipc.Group[]) : Si
|
||||
.map(d => ({
|
||||
id: d.id,
|
||||
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 [
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
import { saveDocuments } from '../../useCases/saveData'
|
||||
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'
|
||||
|
||||
type Dependencies = {
|
||||
documents: ipc.Document[]
|
||||
documents: entities.Document[]
|
||||
updateDocuments: () => Promise<ipc.GetDocumentsResponse>
|
||||
selectedDocumentId: string
|
||||
}
|
||||
@ -12,7 +12,7 @@ type Dependencies = {
|
||||
const createAreaProviderMethods = (dependencies: 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)
|
||||
)
|
||||
|
||||
@ -29,7 +29,7 @@ const createAreaProviderMethods = (dependencies: Dependencies) => {
|
||||
}
|
||||
|
||||
const getProcessedAreasByDocumentId = async (documentId: string) => {
|
||||
let response: ipc.ProcessedArea[] = []
|
||||
let response: entities.ProcessedArea[] = []
|
||||
try {
|
||||
response = await GetProcessedAreasByDocumentId(documentId)
|
||||
} catch (err) {
|
||||
@ -38,15 +38,15 @@ const createAreaProviderMethods = (dependencies: Dependencies) => {
|
||||
return response
|
||||
}
|
||||
|
||||
const requestAddArea = async (documentId: string, area: AddAreaProps): Promise<ipc.Area> => {
|
||||
const response = await RequestAddArea(documentId, new ipc.Area(area))
|
||||
const requestAddArea = async (documentId: string, area: AddAreaProps): Promise<entities.Area> => {
|
||||
const response = await RequestAddArea(documentId, new entities.Area(area))
|
||||
if (response.id) await updateDocuments()
|
||||
saveDocuments()
|
||||
return response
|
||||
}
|
||||
|
||||
const requestUpdateArea = async (updatedArea: AreaProps): Promise<ipc.Area> => {
|
||||
const response = await RequestUpdateArea(new ipc.Area(updatedArea))
|
||||
const requestUpdateArea = async (updatedArea: AreaProps): Promise<entities.Area> => {
|
||||
const response = await RequestUpdateArea(new entities.Area(updatedArea))
|
||||
|
||||
if (response.id) await updateDocuments()
|
||||
saveDocuments()
|
||||
@ -60,7 +60,7 @@ const createAreaProviderMethods = (dependencies: Dependencies) => {
|
||||
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 response = await RequestChangeAreaOrder(areaId, newOrder)
|
||||
|
||||
@ -1,20 +1,20 @@
|
||||
import { saveGroups } from '../../useCases/saveData'
|
||||
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'
|
||||
|
||||
type Dependencies = {
|
||||
selectedDocumentId: string
|
||||
documents: ipc.Document[]
|
||||
documents: entities.Document[]
|
||||
saveDocuments: () => Promise<void>
|
||||
updateDocuments: () => Promise<ipc.GetDocumentsResponse>
|
||||
groups: ipc.Group[]
|
||||
groups: entities.Group[]
|
||||
}
|
||||
|
||||
const createDocumentProviderMethods = (dependencies: 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)
|
||||
)
|
||||
|
||||
@ -42,7 +42,7 @@ const createDocumentProviderMethods = (dependencies: Dependencies) => {
|
||||
}
|
||||
|
||||
const requestUpdateDocument = async (documentProps: UpdateDocumentRequest) => {
|
||||
const response = await RequestUpdateDocument(new ipc.Document(documentProps))
|
||||
const response = await RequestUpdateDocument(new entities.Document(documentProps))
|
||||
await updateDocuments()
|
||||
saveDocuments()
|
||||
return response
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
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'
|
||||
|
||||
type Dependencies = {
|
||||
updateSession: () => Promise<ipc.Session>
|
||||
updateSession: () => Promise<entities.Session>
|
||||
updateDocuments: () => Promise<ipc.GetDocumentsResponse>
|
||||
}
|
||||
|
||||
@ -17,7 +17,7 @@ const createSessionProviderMethods = (dependencies: Dependencies) => {
|
||||
}
|
||||
|
||||
const requestUpdateCurrentUser = async (userProps: UserProps) => {
|
||||
const response = await RequestUpdateCurrentUser(new ipc.User(userProps))
|
||||
const response = await RequestUpdateCurrentUser(new entities.User(userProps))
|
||||
await updateSession()
|
||||
return response
|
||||
}
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
import { saveUserProcessedMarkdown } from '../../useCases/saveData'
|
||||
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 = {}
|
||||
|
||||
const createUserMarkdownProviderMethods = (dependencies?: Dependencies) => {
|
||||
|
||||
const requestUpdateDocumentUserMarkdown = async (documentId: string, markdown: string) => {
|
||||
let response: ipc.UserMarkdown = new ipc.UserMarkdown()
|
||||
let response = new entities.UserMarkdown()
|
||||
try {
|
||||
response = await RequestUpdateDocumentUserMarkdown(documentId, markdown)
|
||||
await saveUserProcessedMarkdown()
|
||||
@ -17,8 +17,8 @@ const createUserMarkdownProviderMethods = (dependencies?: Dependencies) => {
|
||||
return response
|
||||
}
|
||||
|
||||
const getUserMarkdownByDocumentId = async (documentId: string): Promise<ipc.UserMarkdown> => {
|
||||
let response: ipc.UserMarkdown = new ipc.UserMarkdown({})
|
||||
const getUserMarkdownByDocumentId = async (documentId: string): Promise<entities.UserMarkdown> => {
|
||||
let response = new entities.UserMarkdown({})
|
||||
try {
|
||||
response = await GetUserMarkdownByDocumentId(documentId)
|
||||
} 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'
|
||||
|
||||
const makeDefaultProject = (): ProjectContextType => ({
|
||||
id: '',
|
||||
documents: [] as ipc.Document[],
|
||||
groups: [] as ipc.Group[],
|
||||
documents: [] as entities.Document[],
|
||||
groups: [] as entities.Group[],
|
||||
selectedAreaId: '',
|
||||
selectedDocumentId: '',
|
||||
getSelectedDocument: () => new ipc.Document(),
|
||||
getSelectedDocument: () => new entities.Document(),
|
||||
getAreaById: (areaId) => undefined,
|
||||
getProcessedAreasByDocumentId: (documentId) => Promise.resolve([new ipc.ProcessedArea()]),
|
||||
requestAddProcessedArea: (processesArea) => Promise.resolve(new ipc.ProcessedArea()),
|
||||
requestAddArea: (documentId, area) => Promise.resolve(new ipc.Area()),
|
||||
requestUpdateArea: (updatedArea) => Promise.resolve(new ipc.Area()),
|
||||
getProcessedAreasByDocumentId: (documentId) => Promise.resolve([new entities.ProcessedArea()]),
|
||||
requestAddProcessedArea: (processesArea) => Promise.resolve(new entities.ProcessedArea()),
|
||||
requestAddArea: (documentId, area) => Promise.resolve(new entities.Area()),
|
||||
requestUpdateArea: (updatedArea) => Promise.resolve(new entities.Area()),
|
||||
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),
|
||||
requestAddDocumentGroup: (groupName: string) => Promise.resolve(new ipc.Group()),
|
||||
requestUpdateDocumentUserMarkdown: (documentId: string, markdown: string) => Promise.resolve(new ipc.UserMarkdown()),
|
||||
getUserMarkdownByDocumentId: (documentId) => Promise.resolve(new ipc.UserMarkdown),
|
||||
requestAddDocumentGroup: (groupName: string) => Promise.resolve(new entities.Group()),
|
||||
requestUpdateDocumentUserMarkdown: (documentId: string, markdown: string) => Promise.resolve(new entities.UserMarkdown()),
|
||||
getUserMarkdownByDocumentId: (documentId) => Promise.resolve(new entities.UserMarkdown),
|
||||
setSelectedAreaId: (id) => {},
|
||||
setSelectedDocumentId: (id) => {},
|
||||
currentSession: new ipc.Session(),
|
||||
createNewProject: (name: string) => Promise.resolve(new ipc.Session()),
|
||||
requestUpdateCurrentUser: (updatedUserProps: UserProps) => Promise.resolve(new ipc.User()),
|
||||
currentSession: new entities.Session(),
|
||||
createNewProject: (name: string) => Promise.resolve(new entities.Session()),
|
||||
requestUpdateCurrentUser: (updatedUserProps: UserProps) => Promise.resolve(new entities.User()),
|
||||
requestChooseUserAvatar: () => Promise.resolve(''),
|
||||
requestUpdateDocument: ({}) => Promise.resolve(new ipc.Document),
|
||||
requestChangeAreaOrder: (areaId: string, newOrder: number) => Promise.resolve(new ipc.Document()),
|
||||
requestChangeGroupOrder: (groupId: string, newOrder: number) => Promise.resolve(new ipc.Group()),
|
||||
requestUpdateDocument: ({}) => Promise.resolve(new entities.Document),
|
||||
requestChangeAreaOrder: (areaId: string, newOrder: number) => Promise.resolve(new entities.Document()),
|
||||
requestChangeGroupOrder: (groupId: string, newOrder: number) => Promise.resolve(new entities.Group()),
|
||||
getGroupById: (groupId) => undefined,
|
||||
requestSelectProjectByName: (projectName) => Promise.resolve(false),
|
||||
requestUpdateProcessedWordById: (wordId, newTestValue) => Promise.resolve(false),
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
import { createContext, ReactNode, useContext, useEffect, useState } from 'react'
|
||||
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 makeDefaultProject from './makeDefaultProject'
|
||||
import { saveDocuments } from '../../useCases/saveData'
|
||||
@ -19,11 +19,11 @@ export function useProject() {
|
||||
|
||||
type Props = { children: ReactNode, projectProps: ProjectProps }
|
||||
export function ProjectProvider({ children, projectProps }: Props) {
|
||||
const [documents, setDocuments] = useState<ipc.Document[]>(projectProps.documents)
|
||||
const [groups, setGroups] = useState<ipc.Group[]>(projectProps.groups)
|
||||
const [documents, setDocuments] = useState<entities.Document[]>(projectProps.documents)
|
||||
const [groups, setGroups] = useState<entities.Group[]>(projectProps.groups)
|
||||
const [selectedAreaId, setSelectedAreaId] = 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 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 = {
|
||||
id: string,
|
||||
documents: ipc.Document[],
|
||||
groups: ipc.Group[],
|
||||
documents: entities.Document[],
|
||||
groups: entities.Group[],
|
||||
}
|
||||
|
||||
export type AddAreaProps = {
|
||||
@ -32,36 +32,36 @@ export type UpdateDocumentRequest = {
|
||||
groupId?: string,
|
||||
name?: string,
|
||||
path?: string,
|
||||
areas?: ipc.Area[]
|
||||
defaultLanguage?: ipc.Language
|
||||
areas?: entities.Area[]
|
||||
defaultLanguage?: entities.Language
|
||||
}
|
||||
|
||||
export type ProjectContextType = {
|
||||
getSelectedDocument: () => ipc.Document | undefined
|
||||
getAreaById: (areaId: string) => ipc.Area | undefined
|
||||
getProcessedAreasByDocumentId: (documentId: string) => Promise<ipc.ProcessedArea[]>
|
||||
requestAddProcessedArea: (processedArea: ipc.ProcessedArea) => Promise<ipc.ProcessedArea>
|
||||
requestAddArea: (documentId: string, area: AddAreaProps) => Promise<ipc.Area>
|
||||
requestUpdateArea: (area: AreaProps) => Promise<ipc.Area>
|
||||
getSelectedDocument: () => entities.Document | undefined
|
||||
getAreaById: (areaId: string) => entities.Area | undefined
|
||||
getProcessedAreasByDocumentId: (documentId: string) => Promise<entities.ProcessedArea[]>
|
||||
requestAddProcessedArea: (processedArea: entities.ProcessedArea) => Promise<entities.ProcessedArea>
|
||||
requestAddArea: (documentId: string, area: AddAreaProps) => Promise<entities.Area>
|
||||
requestUpdateArea: (area: AreaProps) => Promise<entities.Area>
|
||||
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>
|
||||
requestAddDocumentGroup: (groupName: string) => Promise<ipc.Group>
|
||||
requestUpdateDocumentUserMarkdown: (documentId: string, markdown: string) => Promise<ipc.UserMarkdown>
|
||||
getUserMarkdownByDocumentId: (documentId: string) => Promise<ipc.UserMarkdown>
|
||||
requestAddDocumentGroup: (groupName: string) => Promise<entities.Group>
|
||||
requestUpdateDocumentUserMarkdown: (documentId: string, markdown: string) => Promise<entities.UserMarkdown>
|
||||
getUserMarkdownByDocumentId: (documentId: string) => Promise<entities.UserMarkdown>
|
||||
selectedAreaId: string
|
||||
setSelectedAreaId: (id: string) => void
|
||||
selectedDocumentId: string
|
||||
setSelectedDocumentId: (id: string) => void
|
||||
currentSession: ipc.Session
|
||||
createNewProject: (name: string) => Promise<ipc.Session>
|
||||
requestUpdateCurrentUser: (updatedUserProps: UserProps) => Promise<ipc.User>
|
||||
currentSession: entities.Session
|
||||
createNewProject: (name: string) => Promise<entities.Session>
|
||||
requestUpdateCurrentUser: (updatedUserProps: UserProps) => Promise<entities.User>
|
||||
requestChooseUserAvatar: () => Promise<string>
|
||||
requestUpdateDocument: (request: UpdateDocumentRequest) => Promise<ipc.Document>
|
||||
requestChangeAreaOrder: (areaId: string, newOrder: number) => Promise<ipc.Document>
|
||||
requestChangeGroupOrder: (groupId: string, newOrder: number) => Promise<ipc.Group>
|
||||
getGroupById: (groupId: string) => ipc.Group | undefined
|
||||
requestUpdateDocument: (request: UpdateDocumentRequest) => Promise<entities.Document>
|
||||
requestChangeAreaOrder: (areaId: string, newOrder: number) => Promise<entities.Document>
|
||||
requestChangeGroupOrder: (groupId: string, newOrder: number) => Promise<entities.Group>
|
||||
getGroupById: (groupId: string) => entities.Group | undefined
|
||||
requestSelectProjectByName: (projectName: 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
|
||||
@ -1,6 +1,6 @@
|
||||
import { createScheduler, createWorker } from 'tesseract.js'
|
||||
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 { 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,
|
||||
documentId,
|
||||
order: foundArea.order,
|
||||
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,
|
||||
words: l.words.map((w: any) => new ipc.ProcessedWord({
|
||||
words: l.words.map((w: any) => new entities.ProcessedWord({
|
||||
fullText: w.text,
|
||||
direction: w.direction,
|
||||
confidence: w.confidence,
|
||||
boundingBox: new ipc.ProcessedBoundingBox({
|
||||
boundingBox: new entities.ProcessedBoundingBox({
|
||||
x0: w.bbox.x0,
|
||||
y0: w.bbox.y0,
|
||||
x1: w.bbox.x1,
|
||||
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,
|
||||
confidence: s.confidence,
|
||||
boundingBox: new ipc.ProcessedBoundingBox({
|
||||
boundingBox: new entities.ProcessedBoundingBox({
|
||||
x0: s.bbox.x0,
|
||||
y0: s.bbox.y0,
|
||||
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
|
||||
// This file is automatically generated. DO NOT EDIT
|
||||
import {entities} 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 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>;
|
||||
|
||||
@ -52,12 +53,12 @@ export function RequestSaveLocalUserProcessedMarkdownCollection():Promise<boolea
|
||||
|
||||
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>;
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
export namespace ipc {
|
||||
export namespace entities {
|
||||
|
||||
export class Language {
|
||||
displayName: string;
|
||||
@ -122,39 +122,6 @@ export namespace ipc {
|
||||
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 {
|
||||
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 (
|
||||
"sort"
|
||||
app "textualize/core/App"
|
||||
consts "textualize/core/Consts"
|
||||
document "textualize/core/Document"
|
||||
session "textualize/core/Session"
|
||||
"textualize/entities"
|
||||
storage "textualize/storage"
|
||||
storageEntity "textualize/storage/Entities"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||
)
|
||||
|
||||
type GetDocumentsResponse struct {
|
||||
Documents []Document `json:"documents"`
|
||||
Groups []Group `json:"groups"`
|
||||
Documents []entities.Document `json:"documents"`
|
||||
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)
|
||||
var jsonAreas []Area
|
||||
|
||||
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
|
||||
return entities.Document(*foundDocument)
|
||||
}
|
||||
|
||||
func (c *Channel) GetDocuments() GetDocumentsResponse {
|
||||
@ -51,63 +27,33 @@ func (c *Channel) GetDocuments() GetDocumentsResponse {
|
||||
groups := document.GetGroupCollection().Groups
|
||||
|
||||
response := GetDocumentsResponse{
|
||||
Groups: make([]Group, 0),
|
||||
Documents: make([]Document, 0),
|
||||
Groups: make([]entities.Group, 0),
|
||||
Documents: make([]entities.Document, 0),
|
||||
}
|
||||
|
||||
for _, d := range documents {
|
||||
jsonAreas := make([]Area, 0)
|
||||
for _, a := range d.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),
|
||||
})
|
||||
}
|
||||
|
||||
sort.Slice(jsonAreas, func(i, j int) bool {
|
||||
return jsonAreas[i].Order < jsonAreas[j].Order
|
||||
sortedAreas := d.Areas
|
||||
sort.Slice(sortedAreas, func(i, j int) bool {
|
||||
return sortedAreas[i].Order < sortedAreas[j].Order
|
||||
})
|
||||
|
||||
jsonDocument := Document{
|
||||
Id: d.Id,
|
||||
GroupId: d.GroupId,
|
||||
Name: d.Name,
|
||||
Path: d.Path,
|
||||
ProjectId: d.ProjectId,
|
||||
Areas: jsonAreas,
|
||||
DefaultLanguage: Language(d.DefaultLanguage),
|
||||
}
|
||||
jsonDocument := entities.Document(d)
|
||||
d.Areas = sortedAreas
|
||||
response.Documents = append(response.Documents, jsonDocument)
|
||||
}
|
||||
|
||||
jsonGroups := make([]Group, 0)
|
||||
for _, g := range groups {
|
||||
jsonGroup := Group{
|
||||
Id: g.Id,
|
||||
ParentId: g.ParentId,
|
||||
ProjectId: g.ProjectId,
|
||||
Name: g.Name,
|
||||
Order: g.Order,
|
||||
}
|
||||
jsonGroups = append(jsonGroups, jsonGroup)
|
||||
if len(groups) > 0 {
|
||||
sortedGroups := groups
|
||||
sort.Slice(sortedGroups, func(i, j int) bool {
|
||||
return sortedGroups[i].Order < sortedGroups[j].Order
|
||||
})
|
||||
response.Groups = sortedGroups
|
||||
}
|
||||
|
||||
sort.Slice(jsonGroups, func(i, j int) bool {
|
||||
return jsonGroups[i].Order < jsonGroups[j].Order
|
||||
})
|
||||
|
||||
response.Groups = jsonGroups
|
||||
|
||||
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{
|
||||
Title: "Select an Image",
|
||||
Filters: []runtime.FileFilter{
|
||||
@ -120,7 +66,7 @@ func (c *Channel) RequestAddDocument(groupId string, documentName string) Docume
|
||||
|
||||
if err != nil {
|
||||
runtime.LogError(app.GetInstance().Context, err.Error())
|
||||
return Document{}
|
||||
return entities.Document{}
|
||||
}
|
||||
|
||||
newDocument := document.Entity{
|
||||
@ -133,15 +79,7 @@ func (c *Channel) RequestAddDocument(groupId string, documentName string) Docume
|
||||
|
||||
document.GetDocumentCollection().AddDocument(newDocument)
|
||||
|
||||
documentResponse := Document{
|
||||
Id: newDocument.Id,
|
||||
Name: newDocument.Name,
|
||||
Path: newDocument.Path,
|
||||
GroupId: newDocument.GroupId,
|
||||
ProjectId: newDocument.ProjectId,
|
||||
}
|
||||
|
||||
return documentResponse
|
||||
return entities.Document(newDocument)
|
||||
}
|
||||
|
||||
func (c *Channel) deleteDocumentById(documentId string) bool {
|
||||
@ -164,11 +102,11 @@ func (c *Channel) deleteDocumentById(documentId string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (c *Channel) RequestUpdateDocumentUserMarkdown(documentId string, markdown string) UserMarkdown {
|
||||
func (c *Channel) RequestUpdateDocumentUserMarkdown(documentId string, markdown string) entities.UserMarkdown {
|
||||
markdownCollection := document.GetUserMarkdownCollection()
|
||||
markdownToUpdate := markdownCollection.GetUserMarkdownByDocumentId(documentId)
|
||||
|
||||
newMarkdown := document.UserMarkdown{
|
||||
newMarkdown := entities.UserMarkdown{
|
||||
DocumentId: documentId,
|
||||
Value: markdown,
|
||||
}
|
||||
@ -179,11 +117,7 @@ func (c *Channel) RequestUpdateDocumentUserMarkdown(documentId string, markdown
|
||||
}
|
||||
|
||||
updatedMarkdown := markdownCollection.UpdateUserMarkdown(newMarkdown)
|
||||
return UserMarkdown{
|
||||
Id: updatedMarkdown.Id,
|
||||
DocumentId: updatedMarkdown.DocumentId,
|
||||
Value: updatedMarkdown.Value,
|
||||
}
|
||||
return entities.UserMarkdown(updatedMarkdown)
|
||||
}
|
||||
|
||||
func (c *Channel) deleteDocumentUserMarkdown(documentId string) bool {
|
||||
@ -206,26 +140,15 @@ func (c *Channel) deleteDocumentUserMarkdown(documentId string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (c *Channel) GetUserMarkdownByDocumentId(documentId string) UserMarkdown {
|
||||
func (c *Channel) GetUserMarkdownByDocumentId(documentId string) entities.UserMarkdown {
|
||||
foundUserMarkdown := document.GetUserMarkdownCollection().GetUserMarkdownByDocumentId((documentId))
|
||||
|
||||
response := UserMarkdown{}
|
||||
|
||||
if foundUserMarkdown != nil {
|
||||
response = UserMarkdown{
|
||||
Id: foundUserMarkdown.Id,
|
||||
DocumentId: foundUserMarkdown.DocumentId,
|
||||
Value: foundUserMarkdown.Value,
|
||||
}
|
||||
}
|
||||
|
||||
return response
|
||||
return entities.UserMarkdown(*foundUserMarkdown)
|
||||
}
|
||||
|
||||
func (c *Channel) RequestAddDocumentGroup(name string) Group {
|
||||
func (c *Channel) RequestAddDocumentGroup(name string) entities.Group {
|
||||
groupCollection := document.GetGroupCollection()
|
||||
|
||||
newGroup := document.Group{
|
||||
newGroup := entities.Group{
|
||||
Id: uuid.NewString(),
|
||||
Name: name,
|
||||
ProjectId: session.GetInstance().Project.Id,
|
||||
@ -234,60 +157,41 @@ func (c *Channel) RequestAddDocumentGroup(name string) Group {
|
||||
|
||||
groupCollection.AddDocumentGroup(newGroup)
|
||||
|
||||
response := Group{
|
||||
Id: newGroup.Id,
|
||||
Name: newGroup.Name,
|
||||
ParentId: newGroup.ParentId,
|
||||
ProjectId: newGroup.ProjectId,
|
||||
Order: newGroup.Order,
|
||||
}
|
||||
|
||||
return response
|
||||
return newGroup
|
||||
}
|
||||
|
||||
func (c *Channel) RequestChangeGroupOrder(groupId string, newOrder int) Group {
|
||||
func (c *Channel) RequestChangeGroupOrder(groupId string, newOrder int) entities.Group {
|
||||
groupCollection := document.GetGroupCollection()
|
||||
|
||||
for _, g := range groupCollection.Groups {
|
||||
if g.Id == groupId {
|
||||
// document.GetGroupCollection().Groups[index].Order = newOrder
|
||||
document.GetGroupCollection().GetGroupById(groupId).Order = newOrder
|
||||
} else if g.Order >= newOrder {
|
||||
// document.GetGroupCollection().Groups[index].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)
|
||||
|
||||
if len(foundDocument.Areas) == 0 {
|
||||
return Area{}
|
||||
return entities.Area{}
|
||||
}
|
||||
|
||||
var foundArea document.Area
|
||||
var foundArea entities.Area
|
||||
for i, a := range foundDocument.Areas {
|
||||
if a.Id == areaId {
|
||||
foundArea = foundDocument.Areas[i]
|
||||
}
|
||||
}
|
||||
|
||||
return Area{
|
||||
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),
|
||||
}
|
||||
return foundArea
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
var id string
|
||||
@ -302,7 +206,7 @@ func (c *Channel) RequestAddArea(documentId string, area Area) Area {
|
||||
order = len(foundDocument.Areas)
|
||||
}
|
||||
|
||||
newArea := document.Area{
|
||||
newArea := entities.Area{
|
||||
Id: id,
|
||||
Name: area.Name,
|
||||
StartX: area.StartX,
|
||||
@ -310,30 +214,26 @@ func (c *Channel) RequestAddArea(documentId string, area Area) Area {
|
||||
StartY: area.StartY,
|
||||
EndY: area.EndY,
|
||||
Order: order,
|
||||
Language: consts.Language(area.Language),
|
||||
Language: entities.Language(area.Language),
|
||||
}
|
||||
foundDocument.AddArea(newArea)
|
||||
|
||||
responseArea := area
|
||||
responseArea.Id = id
|
||||
|
||||
return responseArea
|
||||
return newArea
|
||||
}
|
||||
|
||||
func (c *Channel) RequestUpdateArea(updatedArea Area) Area {
|
||||
func (c *Channel) RequestUpdateArea(updatedArea entities.Area) entities.Area {
|
||||
documentOfArea := document.GetDocumentCollection().GetDocumentByAreaId(updatedArea.Id)
|
||||
|
||||
if documentOfArea.Id == "" {
|
||||
return Area{}
|
||||
return entities.Area{}
|
||||
}
|
||||
|
||||
areaToUpdate := documentOfArea.GetAreaById(updatedArea.Id)
|
||||
|
||||
if areaToUpdate.Id == "" {
|
||||
return Area{}
|
||||
return entities.Area{}
|
||||
}
|
||||
|
||||
// TODO: add more prop changes when needed
|
||||
if updatedArea.Name != "" {
|
||||
areaToUpdate.Name = updatedArea.Name
|
||||
}
|
||||
@ -341,16 +241,7 @@ func (c *Channel) RequestUpdateArea(updatedArea Area) Area {
|
||||
areaToUpdate.Order = updatedArea.Order
|
||||
}
|
||||
|
||||
return Area{
|
||||
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),
|
||||
}
|
||||
return *areaToUpdate
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
if documentToUpdate == nil {
|
||||
return Document{}
|
||||
return entities.Document{}
|
||||
}
|
||||
|
||||
if updatedDocument.Id != "" {
|
||||
@ -399,20 +290,20 @@ func (c *Channel) RequestUpdateDocument(updatedDocument Document) Document {
|
||||
documentToUpdate.Path = updatedDocument.Path
|
||||
}
|
||||
if updatedDocument.DefaultLanguage.DisplayName != "" {
|
||||
documentToUpdate.DefaultLanguage = consts.Language(updatedDocument.DefaultLanguage)
|
||||
documentToUpdate.DefaultLanguage = updatedDocument.DefaultLanguage
|
||||
}
|
||||
|
||||
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))
|
||||
|
||||
if documentOfArea == nil {
|
||||
return Document{}
|
||||
return entities.Document{}
|
||||
}
|
||||
|
||||
var foundArea document.Area
|
||||
var foundArea entities.Area
|
||||
for _, a := range documentOfArea.Areas {
|
||||
if a.Id == areaId {
|
||||
foundArea = a
|
||||
@ -421,7 +312,7 @@ func (c *Channel) RequestChangeAreaOrder(areaId string, newOrder int) Document {
|
||||
}
|
||||
|
||||
if foundArea.Id == "" {
|
||||
return Document{}
|
||||
return entities.Document{}
|
||||
}
|
||||
|
||||
processedAreasCollection := document.GetProcessedAreaCollection()
|
||||
@ -455,37 +346,18 @@ func (c *Channel) RequestSaveDocumentCollection() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
var documentsToWrite []storageEntity.Document
|
||||
for _, d := range documentCollection.Documents {
|
||||
var areasToWrite []storageEntity.Area
|
||||
for _, a := range d.Areas {
|
||||
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),
|
||||
})
|
||||
documentCount := len(documentCollection.Documents)
|
||||
writableDocuments := make([]entities.Document, documentCount)
|
||||
for i := 0; i < documentCount; i++ {
|
||||
writableDocuments[i] = entities.Document(documentCollection.Documents[i])
|
||||
}
|
||||
|
||||
successfulWrite := storage.GetDriver().WriteDocumentCollection(storageEntity.DocumentCollection{
|
||||
Documents: documentsToWrite,
|
||||
ProjectId: fullProject.Id,
|
||||
}, projectName)
|
||||
successfulWrite := storage.GetDriver().WriteDocumentCollection(
|
||||
entities.DocumentCollection{
|
||||
ProjectId: fullProject.Id,
|
||||
Documents: writableDocuments,
|
||||
},
|
||||
projectName)
|
||||
|
||||
return successfulWrite
|
||||
}
|
||||
@ -500,15 +372,16 @@ func (c *Channel) RequestSaveGroupCollection() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
var groupsToWrite []storageEntity.Group
|
||||
for _, g := range groupCollection.Groups {
|
||||
groupsToWrite = append(groupsToWrite, storageEntity.Group(g))
|
||||
groupCount := len(groupCollection.Groups)
|
||||
writableGroups := make([]entities.Group, groupCount)
|
||||
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,
|
||||
ProjectId: groupCollection.ProjectId,
|
||||
Groups: groupsToWrite,
|
||||
Groups: writableGroups,
|
||||
}, projectName)
|
||||
|
||||
return successfulWrite
|
||||
@ -518,53 +391,18 @@ func (c *Channel) RequestSaveProcessedTextCollection() bool {
|
||||
processedAreaCollection := document.GetProcessedAreaCollection()
|
||||
projectName := c.GetCurrentSession().Project.Name
|
||||
|
||||
areasToWrite := make([]storageEntity.ProcessedArea, 0)
|
||||
for _, a := range processedAreaCollection.Areas {
|
||||
linesOfAreaToWrite := make([]storageEntity.ProcessedLine, 0)
|
||||
for _, l := range a.Lines {
|
||||
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,
|
||||
})
|
||||
processedAreasCount := len(processedAreaCollection.Areas)
|
||||
writableProcessedAreasAreas := make([]entities.ProcessedArea, processedAreasCount)
|
||||
for i := 0; i < processedAreasCount; i++ {
|
||||
writableProcessedAreasAreas[i] = entities.ProcessedArea(processedAreaCollection.Areas[i])
|
||||
}
|
||||
|
||||
processedAreaCollectionToWrite := storageEntity.ProcessedTextCollection{
|
||||
Areas: areasToWrite,
|
||||
}
|
||||
|
||||
successfulWrite := storage.GetDriver().WriteProcessedTextCollection(processedAreaCollectionToWrite, projectName)
|
||||
successfulWrite := storage.GetDriver().WriteProcessedTextCollection(
|
||||
entities.ProcessedTextCollection{
|
||||
Areas: writableProcessedAreasAreas,
|
||||
},
|
||||
projectName,
|
||||
)
|
||||
return successfulWrite
|
||||
}
|
||||
|
||||
@ -578,14 +416,18 @@ func (c *Channel) RequestSaveLocalUserProcessedMarkdownCollection() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
var valuesToWrite []storageEntity.ProcessedUserMarkdown
|
||||
for _, v := range userProcessedMarkdownCollection.Values {
|
||||
valuesToWrite = append(valuesToWrite, storageEntity.ProcessedUserMarkdown(v))
|
||||
groupCount := len(userProcessedMarkdownCollection.Values)
|
||||
writableMarkdownValues := make([]entities.ProcessedUserMarkdown, groupCount)
|
||||
for i := 0; i < groupCount; i++ {
|
||||
writableMarkdownValues[i] = entities.ProcessedUserMarkdown(userProcessedMarkdownCollection.Values[i])
|
||||
}
|
||||
|
||||
successfulWrite := storage.GetDriver().WriteProcessedUserMarkdownCollection(storageEntity.ProcessedUserMarkdownCollection{
|
||||
Values: valuesToWrite,
|
||||
}, projectName)
|
||||
successfulWrite := storage.GetDriver().WriteProcessedUserMarkdownCollection(
|
||||
entities.ProcessedUserMarkdownCollection{
|
||||
Values: writableMarkdownValues,
|
||||
},
|
||||
projectName,
|
||||
)
|
||||
|
||||
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 (
|
||||
"sort"
|
||||
document "textualize/core/Document"
|
||||
"textualize/entities"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func serializeBoundingBox(bbox document.ProcessedBoundingBox) ProcessedBoundingBox {
|
||||
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 {
|
||||
func (c *Channel) GetProcessedAreasByDocumentId(id string) []entities.ProcessedArea {
|
||||
areas := document.GetProcessedAreaCollection().GetAreasByDocumentId(id)
|
||||
|
||||
var response []ProcessedArea
|
||||
|
||||
for _, a := range areas {
|
||||
response = append(response, serializeProcessedArea(*a))
|
||||
areaCount := len(areas)
|
||||
readableAreas := make([]entities.ProcessedArea, areaCount)
|
||||
for i := 0; i < areaCount; i++ {
|
||||
readableAreas[i] = entities.ProcessedArea(*areas[i])
|
||||
}
|
||||
|
||||
sort.Slice(response, func(i, j int) bool {
|
||||
return response[i].Order < response[j].Order
|
||||
sortedAreas := readableAreas
|
||||
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 {
|
||||
return document.ProcessedBoundingBox{
|
||||
X0: bbox.X0,
|
||||
Y0: bbox.Y0,
|
||||
X1: bbox.X1,
|
||||
Y1: bbox.Y1,
|
||||
}
|
||||
}
|
||||
func (c *Channel) RequestAddProcessedArea(processedArea entities.ProcessedArea) entities.ProcessedArea {
|
||||
|
||||
func deserializeSymbol(symbol ProcessedSymbol) document.ProcessedSymbol {
|
||||
return document.ProcessedSymbol{
|
||||
Text: symbol.Text,
|
||||
Confidence: symbol.Confidence,
|
||||
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
|
||||
for lineIndex, line := range processedArea.Lines {
|
||||
for wordIndex, word := range line.Words {
|
||||
if word.Id == "" {
|
||||
processedArea.Lines[lineIndex].Words[wordIndex].Id = uuid.NewString()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return document.ProcessedWord{
|
||||
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))
|
||||
// }
|
||||
|
||||
document.GetProcessedAreaCollection().AddProcessedArea(processedArea)
|
||||
return processedArea
|
||||
}
|
||||
|
||||
@ -214,7 +73,7 @@ func (c *Channel) RequestUpdateProcessedWordById(wordId string, newTextValue str
|
||||
}
|
||||
|
||||
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,
|
||||
Direction: wordProps.Direction,
|
||||
FullText: newTextValue,
|
||||
|
||||
219
ipc/Session.go
219
ipc/Session.go
@ -5,40 +5,40 @@ import (
|
||||
consts "textualize/core/Consts"
|
||||
document "textualize/core/Document"
|
||||
session "textualize/core/Session"
|
||||
"textualize/entities"
|
||||
storage "textualize/storage"
|
||||
storageEntity "textualize/storage/Entities"
|
||||
|
||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func (c *Channel) GetCurrentSession() Session {
|
||||
func (c *Channel) GetCurrentSession() entities.Session {
|
||||
currentSession := session.GetInstance()
|
||||
|
||||
var sessionUsers []User
|
||||
var sessionUsers []entities.User
|
||||
for _, u := range currentSession.Organization.Users {
|
||||
sessionUsers = append(sessionUsers, User(u))
|
||||
sessionUsers = append(sessionUsers, entities.User(u))
|
||||
}
|
||||
|
||||
currentProject := currentSession.Project
|
||||
currentDefaultProcessLanguage := Language(currentProject.Settings.DefaultProcessLanguage)
|
||||
currentDefaultTranslateTargetLanguage := Language(currentProject.Settings.DefaultTranslateTargetLanguage)
|
||||
project := Project{
|
||||
currentDefaultProcessLanguage := entities.Language(currentProject.Settings.DefaultProcessLanguage)
|
||||
currentDefaultTranslateTargetLanguage := entities.Language(currentProject.Settings.DefaultTranslateTargetLanguage)
|
||||
project := entities.Project{
|
||||
Id: currentProject.Id,
|
||||
Name: currentProject.Name,
|
||||
OrganizationId: currentProject.OrganizationId,
|
||||
Settings: ProjectSettings{
|
||||
Settings: entities.ProjectSettings{
|
||||
DefaultProcessLanguage: currentDefaultProcessLanguage,
|
||||
DefaultTranslateTargetLanguage: currentDefaultTranslateTargetLanguage,
|
||||
IsHosted: currentProject.Settings.IsHosted,
|
||||
},
|
||||
}
|
||||
|
||||
return Session{
|
||||
Project: Project(project),
|
||||
User: User(currentSession.User),
|
||||
Organization: Organization{
|
||||
return entities.Session{
|
||||
Project: project,
|
||||
User: currentSession.User,
|
||||
Organization: entities.Organization{
|
||||
Id: currentSession.Organization.Id,
|
||||
Name: currentSession.Project.Name,
|
||||
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()
|
||||
|
||||
newProject := session.Project{
|
||||
newProject := entities.Project{
|
||||
Id: uuid.NewString(),
|
||||
OrganizationId: currentSession.Project.OrganizationId,
|
||||
Name: name,
|
||||
}
|
||||
|
||||
successfulProjectWrite := storage.GetDriver().WriteProjectData(storageEntity.Project{
|
||||
successfulProjectWrite := storage.GetDriver().WriteProjectData(entities.Project{
|
||||
Id: newProject.Id,
|
||||
OrganizationId: newProject.OrganizationId,
|
||||
Name: newProject.Name,
|
||||
})
|
||||
|
||||
if !successfulProjectWrite {
|
||||
return Session{}
|
||||
return entities.Session{}
|
||||
}
|
||||
|
||||
currentSession.Project = newProject
|
||||
@ -71,14 +71,14 @@ func (c *Channel) CreateNewProject(name string) Session {
|
||||
return c.GetCurrentSession()
|
||||
}
|
||||
|
||||
func (c *Channel) GetCurrentUser() User {
|
||||
return User(session.GetInstance().User)
|
||||
func (c *Channel) GetCurrentUser() entities.User {
|
||||
return session.GetInstance().User
|
||||
}
|
||||
|
||||
func (c *Channel) RequestUpdateCurrentUser(updatedUserRequest User) User {
|
||||
func (c *Channel) RequestUpdateCurrentUser(updatedUserRequest entities.User) entities.User {
|
||||
sessionInstance := session.GetInstance()
|
||||
|
||||
sessionUser := session.User(sessionInstance.User)
|
||||
sessionUser := entities.User(sessionInstance.User)
|
||||
|
||||
if sessionUser.LocalId == "" {
|
||||
sessionUser.LocalId = uuid.NewString()
|
||||
@ -95,14 +95,14 @@ func (c *Channel) RequestUpdateCurrentUser(updatedUserRequest User) User {
|
||||
|
||||
sessionUser.AvatarPath = updatedUserRequest.AvatarPath
|
||||
|
||||
successfulUserWrite := storage.GetDriver().WriteUserData(storageEntity.User(sessionUser))
|
||||
successfulUserWrite := storage.GetDriver().WriteUserData(sessionUser)
|
||||
if !successfulUserWrite {
|
||||
return User{}
|
||||
return entities.User{}
|
||||
}
|
||||
|
||||
sessionInstance.UpdateCurrentUser(sessionUser)
|
||||
|
||||
return User(sessionInstance.User)
|
||||
return sessionInstance.User
|
||||
}
|
||||
|
||||
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()
|
||||
response := make([]Project, 0)
|
||||
|
||||
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
|
||||
return readLocalProjects
|
||||
}
|
||||
|
||||
func (c *Channel) GetProjectByName(projectName string) Project {
|
||||
func (c *Channel) GetProjectByName(projectName string) entities.Project {
|
||||
foundProject := storage.GetDriver().ReadProjectDataByName(projectName)
|
||||
|
||||
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,
|
||||
},
|
||||
}
|
||||
return foundProject
|
||||
}
|
||||
|
||||
func (c *Channel) RequestChangeSessionProjectByName(projectName string) bool {
|
||||
@ -171,139 +142,57 @@ func (c *Channel) RequestChangeSessionProjectByName(projectName string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
session.GetInstance().Project = session.Project{
|
||||
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,
|
||||
},
|
||||
}
|
||||
session.GetInstance().Project = foundProject
|
||||
|
||||
localDocumentCollection := storageDriver.ReadDocumentCollection(projectName)
|
||||
newDocuments := make([]document.Entity, 0)
|
||||
for _, d := range localDocumentCollection.Documents {
|
||||
newAreas := make([]document.Area, 0)
|
||||
for _, a := range d.Areas {
|
||||
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),
|
||||
})
|
||||
documentCount := len(localDocumentCollection.Documents)
|
||||
readableDocuments := make([]document.Entity, documentCount)
|
||||
for i := 0; i < documentCount; i++ {
|
||||
readableDocuments[i] = document.Entity(localDocumentCollection.Documents[i])
|
||||
}
|
||||
newDocumentColllection := document.DocumentCollection{
|
||||
Documents: newDocuments,
|
||||
document.SetDocumentCollection(document.DocumentCollection{
|
||||
Documents: readableDocuments,
|
||||
ProjectId: foundProject.Id,
|
||||
}
|
||||
document.SetDocumentCollection(newDocumentColllection)
|
||||
})
|
||||
|
||||
localGroupsCollection := storageDriver.ReadGroupCollection(projectName)
|
||||
newGroups := make([]document.Group, 0)
|
||||
for _, g := range localGroupsCollection.Groups {
|
||||
newGroups = append(newGroups, document.Group(g))
|
||||
groupCount := len(localGroupsCollection.Groups)
|
||||
readableGroups := make([]entities.Group, groupCount)
|
||||
for i := 0; i < groupCount; i++ {
|
||||
readableGroups[i] = entities.Group(localGroupsCollection.Groups[i])
|
||||
}
|
||||
newGroupCollection := document.GroupCollection{
|
||||
document.SetGroupCollection(document.GroupCollection{
|
||||
Id: localGroupsCollection.Id,
|
||||
ProjectId: localGroupsCollection.ProjectId,
|
||||
Groups: newGroups,
|
||||
}
|
||||
document.SetGroupCollection(newGroupCollection)
|
||||
Groups: readableGroups,
|
||||
})
|
||||
|
||||
// Processed Texts
|
||||
|
||||
localProcessedAreaCollection := storageDriver.ReadProcessedTextCollection(projectName)
|
||||
newAreas := make([]document.ProcessedArea, 0)
|
||||
for _, a := range localProcessedAreaCollection.Areas {
|
||||
linesOfArea := make([]document.ProcessedLine, 0)
|
||||
for _, l := range a.Lines {
|
||||
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,
|
||||
})
|
||||
areaCount := len(localProcessedAreaCollection.Areas)
|
||||
readableAreas := make([]entities.ProcessedArea, areaCount)
|
||||
for i := 0; i < areaCount; i++ {
|
||||
readableAreas[i] = entities.ProcessedArea(localProcessedAreaCollection.Areas[i])
|
||||
}
|
||||
|
||||
document.SetProcessedAreaCollection(document.ProcessedAreaCollection{
|
||||
Areas: newAreas,
|
||||
Areas: readableAreas,
|
||||
})
|
||||
|
||||
// UserProcessedMarkdown
|
||||
|
||||
localUserProcessedMarkdown := storageDriver.ReadProcessedUserMarkdownCollection(projectName)
|
||||
|
||||
newUserProcessedMarkdown := make([]document.UserMarkdown, 0)
|
||||
for _, v := range localUserProcessedMarkdown.Values {
|
||||
newUserProcessedMarkdown = append(newUserProcessedMarkdown, document.UserMarkdown{
|
||||
Id: v.Id,
|
||||
DocumentId: v.DocumentId,
|
||||
Value: v.Value,
|
||||
})
|
||||
userProcessedMarkdownCount := len(localUserProcessedMarkdown.Values)
|
||||
readableUserProcessedMarkdown := make([]entities.UserMarkdown, userProcessedMarkdownCount)
|
||||
for i := 0; i < userProcessedMarkdownCount; i++ {
|
||||
readableUserProcessedMarkdown[i] = entities.UserMarkdown(localUserProcessedMarkdown.Values[i])
|
||||
}
|
||||
|
||||
document.SetUserMarkdownCollection(document.UserMarkdownCollection{
|
||||
Values: newUserProcessedMarkdown,
|
||||
Values: readableUserProcessedMarkdown,
|
||||
})
|
||||
|
||||
// End UserProcessedMarkdown
|
||||
|
||||
return session.GetInstance().Project.Id == foundProject.Id
|
||||
}
|
||||
|
||||
func (c *Channel) GetSuppportedLanguages() []Language {
|
||||
func (c *Channel) GetSuppportedLanguages() []entities.Language {
|
||||
supportedLanguages := consts.GetSuppportedLanguages()
|
||||
|
||||
var response []Language
|
||||
|
||||
for _, l := range supportedLanguages {
|
||||
response = append(response, Language(l))
|
||||
}
|
||||
|
||||
return response
|
||||
return supportedLanguages
|
||||
}
|
||||
|
||||
@ -2,20 +2,20 @@ package storage
|
||||
|
||||
import (
|
||||
"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, "", " ")
|
||||
writeError := WriteDataToAppDir(jsonData, "/projects/"+projectName+"/", "Documents.json")
|
||||
return writeError == nil
|
||||
}
|
||||
|
||||
func (d LocalDriver) ReadDocumentCollection(projectName string) entity.DocumentCollection {
|
||||
documentCollectionData := entity.DocumentCollection{}
|
||||
func (d LocalDriver) ReadDocumentCollection(projectName string) entities.DocumentCollection {
|
||||
documentCollectionData := entities.DocumentCollection{}
|
||||
readError := AssignFileDataToStruct("/projects/"+projectName+"/Documents.json", &documentCollectionData)
|
||||
if readError != nil {
|
||||
return entity.DocumentCollection{}
|
||||
return entities.DocumentCollection{}
|
||||
}
|
||||
|
||||
return documentCollectionData
|
||||
|
||||
@ -2,20 +2,20 @@ package storage
|
||||
|
||||
import (
|
||||
"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, "", " ")
|
||||
writeError := WriteDataToAppDir(jsonData, "/projects/"+projectName+"/", "Groups.json")
|
||||
return writeError == nil
|
||||
}
|
||||
|
||||
func (d LocalDriver) ReadGroupCollection(projectName string) entity.GroupCollection {
|
||||
collectionData := entity.GroupCollection{}
|
||||
func (d LocalDriver) ReadGroupCollection(projectName string) entities.GroupCollection {
|
||||
collectionData := entities.GroupCollection{}
|
||||
readError := AssignFileDataToStruct("/projects/"+projectName+"/Groups.json", &collectionData)
|
||||
if readError != nil {
|
||||
return entity.GroupCollection{}
|
||||
return entities.GroupCollection{}
|
||||
}
|
||||
|
||||
return collectionData
|
||||
|
||||
@ -2,36 +2,36 @@ package storage
|
||||
|
||||
import (
|
||||
"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, "", " ")
|
||||
writeError := WriteDataToAppDir(jsonData, "/projects/"+projectName+"/", "ProcessedTexts.json")
|
||||
return writeError == nil
|
||||
}
|
||||
|
||||
func (d LocalDriver) ReadProcessedTextCollection(projectName string) entity.ProcessedTextCollection {
|
||||
collectionData := entity.ProcessedTextCollection{}
|
||||
func (d LocalDriver) ReadProcessedTextCollection(projectName string) entities.ProcessedTextCollection {
|
||||
collectionData := entities.ProcessedTextCollection{}
|
||||
readError := AssignFileDataToStruct("/projects/"+projectName+"/ProcessedTexts.json", &collectionData)
|
||||
if readError != nil {
|
||||
return entity.ProcessedTextCollection{}
|
||||
return entities.ProcessedTextCollection{}
|
||||
}
|
||||
|
||||
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, "", " ")
|
||||
writeError := WriteDataToAppDir(jsonData, "/projects/"+projectName+"/", "UserProcessedMarkdown.json")
|
||||
return writeError == nil
|
||||
}
|
||||
|
||||
func (d LocalDriver) ReadProcessedUserMarkdownCollection(projectName string) entity.ProcessedUserMarkdownCollection {
|
||||
collectionData := entity.ProcessedUserMarkdownCollection{}
|
||||
func (d LocalDriver) ReadProcessedUserMarkdownCollection(projectName string) entities.ProcessedUserMarkdownCollection {
|
||||
collectionData := entities.ProcessedUserMarkdownCollection{}
|
||||
readError := AssignFileDataToStruct("/projects/"+projectName+"/UserProcessedMarkdown.json", &collectionData)
|
||||
if readError != nil {
|
||||
return entity.ProcessedUserMarkdownCollection{}
|
||||
return entities.ProcessedUserMarkdownCollection{}
|
||||
}
|
||||
|
||||
return collectionData
|
||||
|
||||
@ -3,27 +3,27 @@ package storage
|
||||
import (
|
||||
"encoding/json"
|
||||
"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, "", " ")
|
||||
writeError := WriteDataToAppDir(jsonData, "/projects/"+project.Name+"/", "Project.json")
|
||||
return writeError == nil
|
||||
}
|
||||
|
||||
func (d LocalDriver) ReadProjectDataByName(projectName string) storage.Project {
|
||||
projectData := storage.Project{}
|
||||
func (d LocalDriver) ReadProjectDataByName(projectName string) entities.Project {
|
||||
projectData := entities.Project{}
|
||||
readError := AssignFileDataToStruct("/projects/"+projectName+"/Project.json", &projectData)
|
||||
if readError != nil {
|
||||
return storage.Project{}
|
||||
return entities.Project{}
|
||||
}
|
||||
|
||||
return projectData
|
||||
}
|
||||
|
||||
func (d LocalDriver) ReadAllProjects() []storage.Project {
|
||||
localProjects := make([]storage.Project, 0)
|
||||
func (d LocalDriver) ReadAllProjects() []entities.Project {
|
||||
localProjects := make([]entities.Project, 0)
|
||||
|
||||
subdirectory := "/projects/"
|
||||
isLocalStorageDirectoryCreated := createLocalStorageSubDirIfNeeded(subdirectory)
|
||||
|
||||
@ -2,20 +2,20 @@ package storage
|
||||
|
||||
import (
|
||||
"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, "", " ")
|
||||
writeError := WriteDataToAppDir(jsonData, "/", "User.json")
|
||||
return writeError == nil
|
||||
}
|
||||
|
||||
func (d LocalDriver) ReadUserData() storage.User {
|
||||
userData := storage.User{}
|
||||
func (d LocalDriver) ReadUserData() entities.User {
|
||||
userData := entities.User{}
|
||||
readError := AssignFileDataToStruct("/User.json", &userData)
|
||||
if readError != nil {
|
||||
return storage.User{}
|
||||
return entities.User{}
|
||||
}
|
||||
|
||||
return userData
|
||||
|
||||
@ -1,24 +1,24 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
entity "textualize/storage/Entities"
|
||||
"textualize/entities"
|
||||
local "textualize/storage/Local"
|
||||
)
|
||||
|
||||
type Driver interface {
|
||||
WriteUserData(entity.User) bool
|
||||
ReadUserData() entity.User
|
||||
WriteProjectData(entity.Project) bool
|
||||
ReadProjectDataByName(string) entity.Project
|
||||
ReadAllProjects() []entity.Project
|
||||
WriteDocumentCollection(entity.DocumentCollection, string) bool
|
||||
ReadDocumentCollection(string) entity.DocumentCollection
|
||||
WriteGroupCollection(entity.GroupCollection, string) bool
|
||||
ReadGroupCollection(string) entity.GroupCollection
|
||||
WriteProcessedTextCollection(entity.ProcessedTextCollection, string) bool
|
||||
ReadProcessedTextCollection(string) entity.ProcessedTextCollection
|
||||
WriteProcessedUserMarkdownCollection(entity.ProcessedUserMarkdownCollection, string) bool
|
||||
ReadProcessedUserMarkdownCollection(string) entity.ProcessedUserMarkdownCollection
|
||||
WriteUserData(entities.User) bool
|
||||
ReadUserData() entities.User
|
||||
WriteProjectData(entities.Project) bool
|
||||
ReadProjectDataByName(string) entities.Project
|
||||
ReadAllProjects() []entities.Project
|
||||
WriteDocumentCollection(entities.DocumentCollection, string) bool
|
||||
ReadDocumentCollection(string) entities.DocumentCollection
|
||||
WriteGroupCollection(entities.GroupCollection, string) bool
|
||||
ReadGroupCollection(string) entities.GroupCollection
|
||||
WriteProcessedTextCollection(entities.ProcessedTextCollection, string) bool
|
||||
ReadProcessedTextCollection(string) entities.ProcessedTextCollection
|
||||
WriteProcessedUserMarkdownCollection(entities.ProcessedUserMarkdownCollection, string) bool
|
||||
ReadProcessedUserMarkdownCollection(string) entities.ProcessedUserMarkdownCollection
|
||||
}
|
||||
|
||||
var driverInstance Driver
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 70 KiB |
Loading…
x
Reference in New Issue
Block a user