mirror of https://github.com/doccano/doccano.git
8 changed files with 40 additions and 88 deletions
Split View
Diff Options
-
12frontend/domain/models/label/label.ts
-
10frontend/domain/models/member/member.ts
-
36frontend/domain/models/option/option.ts
-
8frontend/domain/models/tag/tag.ts
-
13frontend/repositories/label/apiLabelRepository.ts
-
3frontend/repositories/member/apiMemberRepository.ts
-
23frontend/repositories/option/apiOptionRepository.ts
-
23frontend/services/application/label/labelApplicationService.ts
@ -1,37 +1,3 @@ |
|||
export class PageNumber { |
|||
num: number |
|||
|
|||
constructor(public page: number) { |
|||
if (typeof page === 'string' && /^\d+$/.test(page)) { |
|||
this.num = parseInt(page, 10) |
|||
} |
|||
if (typeof page === 'number' && page > 0) { |
|||
this.num = page |
|||
} |
|||
this.num = 1 |
|||
} |
|||
} |
|||
|
|||
export class OptionItem { |
|||
constructor(public page: number, public q?: string, public isChecked?: string) {} |
|||
|
|||
static valueOf({ |
|||
page, |
|||
q = '', |
|||
isChecked = '' |
|||
}: { |
|||
page: number |
|||
q?: string |
|||
isChecked?: string |
|||
}): OptionItem { |
|||
return new OptionItem(page, q, isChecked) |
|||
} |
|||
|
|||
toObject(): Object { |
|||
return { |
|||
page: this.page, |
|||
q: this.q, |
|||
isChecked: this.isChecked |
|||
} |
|||
} |
|||
constructor(public page: number, public q = '', public isChecked = '') {} |
|||
} |
@ -1,11 +1,3 @@ |
|||
export class TagItem { |
|||
constructor(readonly id: number, readonly text: string, readonly project: string) {} |
|||
|
|||
toObject(): Object { |
|||
return { |
|||
id: this.id, |
|||
text: this.text, |
|||
project: this.project |
|||
} |
|||
} |
|||
} |
@ -1,19 +1,32 @@ |
|||
import { OptionRepository } from '../../domain/models/option/optionRepository' |
|||
import { OptionItem } from '~/domain/models/option/option' |
|||
import { OptionRepository } from '@/domain/models/option/optionRepository' |
|||
import { OptionItem } from '@/domain/models/option/option' |
|||
|
|||
function toPayload(item: OptionItem): { [key: string]: any } { |
|||
return { |
|||
page: item.page, |
|||
q: item.q, |
|||
isChecked: item.isChecked |
|||
} |
|||
} |
|||
|
|||
export class LocalStorageOptionRepository implements OptionRepository { |
|||
findById(projectId: string): OptionItem { |
|||
const checkpoint = this.loadCheckpoint() |
|||
return OptionItem.valueOf(checkpoint[projectId] ? checkpoint[projectId] : { page: 1 }) |
|||
if (checkpoint[projectId]) { |
|||
const option = checkpoint[projectId] |
|||
return new OptionItem(option.page, option.q, option.isChecked) |
|||
} else { |
|||
return new OptionItem(1) |
|||
} |
|||
} |
|||
|
|||
save(projectId: string, option: OptionItem): void { |
|||
const checkpoint = this.loadCheckpoint() |
|||
checkpoint[projectId] = option.toObject() |
|||
checkpoint[projectId] = toPayload(option) |
|||
localStorage.setItem('checkpoint', JSON.stringify(checkpoint)) |
|||
} |
|||
|
|||
loadCheckpoint() { |
|||
loadCheckpoint(): { [key: string]: any } { |
|||
const item = localStorage.getItem('checkpoint') || '{}' |
|||
return JSON.parse(item) |
|||
} |
|||
|
Write
Preview
Loading…
Cancel
Save