Revize 0db53e25
Přidáno uživatelem Jaroslav Hrubý před asi 2 roky(ů)
webapp/pages/documents/annotator/index.tsx | ||
---|---|---|
3 | 3 |
|
4 | 4 |
import { useUnauthRedirect } from '../../../hooks'; |
5 | 5 |
import { useRouter } from 'next/router'; |
6 |
import { Button, Table, Tag, Typography } from 'antd'; |
|
6 |
import { Button, Input, Space, Table, Tag, Typography } from 'antd';
|
|
7 | 7 |
import { faFileLines } from '@fortawesome/free-solid-svg-icons'; |
8 | 8 |
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; |
9 | 9 |
import { LoggedUserContext } from '../../../contexts/LoggedUserContext'; |
10 | 10 |
import { MainLayout } from '../../../layouts/MainLayout'; |
11 | 11 |
import { userController } from '../../../controllers'; |
12 | 12 |
import { AnnotationListInfo } from '../../../api'; |
13 |
import { |
|
14 |
CheckCircleOutlined, |
|
15 |
ClockCircleOutlined, |
|
16 |
SearchOutlined, |
|
17 |
SyncOutlined, |
|
18 |
} from '@ant-design/icons'; |
|
13 | 19 |
|
14 | 20 |
function UserDocumentPage() { |
15 | 21 |
const redirecting = useUnauthRedirect('/login'); |
16 | 22 |
const { logout, role } = useContext(LoggedUserContext); |
17 |
const router = useRouter(); |
|
18 | 23 |
const [documents, setDocuments] = useState<AnnotationListInfo[]>([]); |
24 |
const router = useRouter(); |
|
19 | 25 |
|
20 | 26 |
useEffect(() => { |
21 | 27 |
async function fetchData() { |
... | ... | |
33 | 39 |
} |
34 | 40 |
}, [logout, redirecting, role, router]); |
35 | 41 |
|
42 |
const handleSearch = ( |
|
43 |
selectedKeys: React.SetStateAction<string>[], |
|
44 |
confirm: () => void |
|
45 |
) => { |
|
46 |
confirm(); |
|
47 |
}; |
|
48 |
|
|
49 |
const handleReset = (clearFilters: () => void) => { |
|
50 |
clearFilters(); |
|
51 |
}; |
|
52 |
|
|
53 |
const getColumnSearchProps = (dataIndex: string, searchLabel: string) => ({ |
|
54 |
// @ts-ignore |
|
55 |
filterDropdown: ({ setSelectedKeys, selectedKeys, confirm, clearFilters }) => ( |
|
56 |
<div style={{ padding: 8 }}> |
|
57 |
<Input |
|
58 |
placeholder={`Vyhledat ${searchLabel}`} |
|
59 |
value={selectedKeys[0]} |
|
60 |
onChange={(e) => |
|
61 |
setSelectedKeys(e.target.value ? [e.target.value] : []) |
|
62 |
} |
|
63 |
onPressEnter={() => handleSearch(selectedKeys, confirm)} |
|
64 |
style={{ marginBottom: 8, display: 'block' }} |
|
65 |
/> |
|
66 |
<Space> |
|
67 |
<Button |
|
68 |
type="primary" |
|
69 |
onClick={() => handleSearch(selectedKeys, confirm)} |
|
70 |
icon={<SearchOutlined />} |
|
71 |
style={{ width: 90 }} |
|
72 |
> |
|
73 |
Hledat |
|
74 |
</Button> |
|
75 |
<Button |
|
76 |
onClick={() => handleReset(clearFilters)} |
|
77 |
style={{ width: 90 }} |
|
78 |
> |
|
79 |
Smazat |
|
80 |
</Button> |
|
81 |
</Space> |
|
82 |
</div> |
|
83 |
), |
|
84 |
filterIcon: (filtered: any) => ( |
|
85 |
<SearchOutlined style={{ color: filtered ? '#1890ff' : undefined }} /> |
|
86 |
), |
|
87 |
onFilter: (value: string, record: { [x: string]: { toString: () => string } }) => |
|
88 |
record[dataIndex] |
|
89 |
? record[dataIndex].toString().toLowerCase().includes(value.toLowerCase()) |
|
90 |
: '', |
|
91 |
}); |
|
92 |
|
|
36 | 93 |
const columns = [ |
37 | 94 |
{ |
38 | 95 |
title: 'Název dokumentu', |
39 | 96 |
dataIndex: 'documentName', |
40 | 97 |
key: 'documentName', |
98 |
...getColumnSearchProps('documentName', 'název'), |
|
41 | 99 |
}, |
42 | 100 |
{ |
43 | 101 |
title: 'Stav anotace', |
... | ... | |
46 | 104 |
render: (state: string) => { |
47 | 105 |
let color = 'green'; |
48 | 106 |
let label = 'Hotovo'; |
107 |
let icon = <CheckCircleOutlined />; |
|
49 | 108 |
if (state === 'NEW') { |
50 | 109 |
color = 'volcano'; |
51 | 110 |
label = 'Nový'; |
111 |
icon = <ClockCircleOutlined />; |
|
52 | 112 |
} |
53 | 113 |
if (state === 'IN_PROGRESS') { |
54 | 114 |
color = 'orange'; |
55 | 115 |
label = 'Rozpracováno'; |
116 |
icon = <SyncOutlined spin />; |
|
56 | 117 |
} |
57 | 118 |
return ( |
58 |
<Tag color={color} key={label}> |
|
119 |
<Tag icon={icon} color={color} key={label}>
|
|
59 | 120 |
{label.toUpperCase()} |
60 | 121 |
</Tag> |
61 | 122 |
); |
62 | 123 |
}, |
124 |
filters: [ |
|
125 |
{ |
|
126 |
text: 'Nový', |
|
127 |
value: 'NEW', |
|
128 |
}, |
|
129 |
{ |
|
130 |
text: 'Rozpracováno', |
|
131 |
value: 'IN_PROGRESS', |
|
132 |
}, |
|
133 |
{ |
|
134 |
text: 'Hotovo', |
|
135 |
value: 'DONE', |
|
136 |
}, |
|
137 |
], |
|
138 |
// @ts-ignore |
|
139 |
onFilter: (value, record) => record.state.indexOf(value) === 0, |
|
140 |
// @ts-ignore |
|
141 |
sorter: (a, b) => a.state.length - b.state.length, |
|
142 |
sortDirections: ['descend', 'ascend'], |
|
63 | 143 |
}, |
64 | 144 |
{ |
65 | 145 |
title: '', |
... | ... | |
83 | 163 |
<FontAwesomeIcon icon={faFileLines} /> Dokumenty |
84 | 164 |
</Typography.Title> |
85 | 165 |
<Table |
166 |
locale={{ |
|
167 |
triggerDesc: 'Seřadit sestupně', |
|
168 |
triggerAsc: 'Seřadit vzestupně', |
|
169 |
cancelSort: 'Vypnout řazení', |
|
170 |
}} |
|
171 |
// @ts-ignore |
|
86 | 172 |
columns={columns} |
173 |
// @ts-ignore |
|
87 | 174 |
dataSource={documents} |
88 | 175 |
size="small" |
89 | 176 |
scroll={{ y: 500 }} |
Také k dispozici: Unified diff
Document filtering implemented