Skip to content

Commit 0c2898f

Browse files
authored
Merge pull request #182 from siemens/admin_licenses
feat(admin_licenses): Add functionality to upload license archive
2 parents e6fa710 + f484df7 commit 0c2898f

File tree

9 files changed

+230
-7
lines changed

9 files changed

+230
-7
lines changed

messages/en.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,17 @@
748748
"Creator Group": "Creator Group",
749749
"ECC Assessor": "ECC Assessor",
750750
"ECC Assessor Group": "ECC Assessor Group",
751-
"ECC Assessment Date": "ECC Assessment Date"
751+
"ECC Assessment Date": "ECC Assessment Date",
752+
"License Administration": "License Administration",
753+
"Download License Archive": "Download License Archive",
754+
"Import SPDX Information": "Import SPDX Information",
755+
"Import OSADL Information": "Import OSADL Information",
756+
"Delete all License Information": "Delete all License Information",
757+
"Upload License Archive": "Upload License Archive",
758+
"Upload Licenses": "Upload Licenses",
759+
"Overwrite if external ids match": "Overwrite if external ids match",
760+
"Overwrite if ids match": "Overwrite if ids match",
761+
"Licenses uploaded successfully": "Licenses uploaded successfully",
762+
"Please select a file": "Please select a file!"
752763
}
753764
}

messages/ja.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,17 @@
749749
"Creator Group": "Creator Group",
750750
"ECC Assessor": "ECC Assessor",
751751
"ECC Assessor Group": "ECC Assessor Group",
752-
"ECC Assessment Date": "ECC Assessment Date"
752+
"ECC Assessment Date": "ECC Assessment Date",
753+
"License Administration": "License Administration",
754+
"Download License Archive": "Download License Archive",
755+
"Import SPDX Information": "Import SPDX Information",
756+
"Import OSADL Information": "Import OSADL Information",
757+
"Delete all License Information": "Delete all License Information",
758+
"Upload License Archive": "Upload License Archive",
759+
"Upload Licenses": "Upload Licenses",
760+
"Overwrite if external ids match": "Overwrite if external ids match",
761+
"Overwrite if ids match": "Overwrite if ids match",
762+
"Licenses uploaded successfully": "Licenses uploaded successfully",
763+
"Please select a file": "Please select a file!"
753764
}
754765
}

messages/pt-BR.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,17 @@
748748
"Creator Group": "Creator Group",
749749
"ECC Assessor": "ECC Assessor",
750750
"ECC Assessor Group": "ECC Assessor Group",
751-
"ECC Assessment Date": "ECC Assessment Date"
751+
"ECC Assessment Date": "ECC Assessment Date",
752+
"License Administration": "License Administration",
753+
"Download License Archive": "Download License Archive",
754+
"Import SPDX Information": "Import SPDX Information",
755+
"Import OSADL Information": "Import OSADL Information",
756+
"Delete all License Information": "Delete all License Information",
757+
"Upload License Archive": "Upload License Archive",
758+
"Upload Licenses": "Upload Licenses",
759+
"Overwrite if external ids match": "Overwrite if external ids match",
760+
"Overwrite if ids match": "Overwrite if ids match",
761+
"Licenses uploaded successfully": "Licenses uploaded successfully",
762+
"Please select a file": "Please select a file!"
752763
}
753764
}

messages/vi.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,17 @@
747747
"Creator Group": "Creator Group",
748748
"ECC Assessor": "ECC Assessor",
749749
"ECC Assessor Group": "ECC Assessor Group",
750-
"ECC Assessment Date": "ECC Assessment Date"
750+
"ECC Assessment Date": "ECC Assessment Date",
751+
"License Administration": "License Administration",
752+
"Download License Archive": "Download License Archive",
753+
"Import SPDX Information": "Import SPDX Information",
754+
"Import OSADL Information": "Import OSADL Information",
755+
"Delete all License Information": "Delete all License Information",
756+
"Upload License Archive": "Upload License Archive",
757+
"Upload Licenses": "Upload Licenses",
758+
"Overwrite if external ids match": "Overwrite if external ids match",
759+
"Overwrite if ids match": "Overwrite if ids match",
760+
"Licenses uploaded successfully": "Licenses uploaded successfully",
761+
"Please select a file": "Please select a file!"
751762
}
752763
}

messages/zh-CN.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,17 @@
747747
"Creator Group": "Creator Group",
748748
"ECC Assessor": "ECC Assessor",
749749
"ECC Assessor Group": "ECC Assessor Group",
750-
"ECC Assessment Date": "ECC Assessment Date"
750+
"ECC Assessment Date": "ECC Assessment Date",
751+
"License Administration": "License Administration",
752+
"Download License Archive": "Download License Archive",
753+
"Import SPDX Information": "Import SPDX Information",
754+
"Import OSADL Information": "Import OSADL Information",
755+
"Delete all License Information": "Delete all License Information",
756+
"Upload License Archive": "Upload License Archive",
757+
"Upload Licenses": "Upload Licenses",
758+
"Overwrite if external ids match": "Overwrite if external ids match",
759+
"Overwrite if ids match": "Overwrite if ids match",
760+
"Licenses uploaded successfully": "Licenses uploaded successfully",
761+
"Please select a file": "Please select a file!"
751762
}
752763
}

src/app/[locale]/admin/components/Admin.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const AdminMainPage = () => {
4747
<FiEdit2 /> {t('Bulk Release Edit')}
4848
</button>
4949
</Link>
50-
<Link href='#'>
50+
<Link href='/admin/licenses'>
5151
<button type='button' className='btn btn-secondary mb-2 mx-2' style={{ width: '210px' }}>
5252
<BsFileEarmarkText /> {t('Licenses')}
5353
</button>
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
// Copyright (C) Siemens AG, 2023. Part of the SW360 Frontend Project.
2+
3+
// This program and the accompanying materials are made
4+
// available under the terms of the Eclipse Public License 2.0
5+
// which is available at https://www.eclipse.org/legal/epl-2.0/
6+
7+
// SPDX-License-Identifier: EPL-2.0
8+
// License-Filename: LICENSE
9+
10+
'use client'
11+
12+
import { HttpStatus, ToastData } from '@/object-types'
13+
import { ApiUtils } from '@/utils'
14+
import { getSession, signIn } from 'next-auth/react'
15+
import { useTranslations } from 'next-intl'
16+
import { ToastMessage } from 'next-sw360'
17+
import { useRef, useState } from 'react'
18+
import { ToastContainer } from 'react-bootstrap'
19+
20+
export default function AddVendor() {
21+
const t = useTranslations('default')
22+
const file = useRef<File | undefined>()
23+
24+
const [toastData, setToastData] = useState<ToastData>({
25+
show: false,
26+
type: '',
27+
message: '',
28+
contextual: '',
29+
})
30+
31+
const alert = (show_data: boolean, status_type: string, message: string, contextual: string) => {
32+
setToastData({
33+
show: show_data,
34+
type: status_type,
35+
message: message,
36+
contextual: contextual,
37+
})
38+
}
39+
40+
const handleFileChange = (e: React.ChangeEvent<HTMLInputElement>) => {
41+
if (!e.currentTarget.files && e.currentTarget.files.length === 0) {
42+
return
43+
}
44+
file.current = e.currentTarget.files[0]
45+
}
46+
47+
const uploadLicenses = async () => {
48+
try {
49+
if (!file.current) {
50+
alert(true, 'Error', t('Please select a file'), 'danger')
51+
return
52+
}
53+
const formData = new FormData()
54+
formData.append('licenseFile', file.current, file.current.name)
55+
56+
const session = await getSession()
57+
58+
const response = await ApiUtils.POST('licenses/upload', formData, session.user.access_token)
59+
if (response.status === HttpStatus.UNAUTHORIZED) {
60+
signIn()
61+
} else if (response.status === HttpStatus.OK) {
62+
alert(true, 'Success', t('Licenses uploaded successfully'), 'success')
63+
} else {
64+
const data = await response.json()
65+
console.log(data)
66+
alert(true, 'Error', t('Something went wrong'), 'danger')
67+
}
68+
} catch (err) {
69+
console.error(err)
70+
}
71+
}
72+
73+
return (
74+
<>
75+
<div className='mt-4 mx-5'>
76+
<div className='row'>
77+
<div className='col-lg-8'>
78+
<button type='button' className='btn btn-primary col-auto me-2'>
79+
{t('Download License Archive')}
80+
</button>
81+
<button type='button' className='btn btn-primary col-auto me-2'>
82+
{t('Import SPDX Information')}
83+
</button>
84+
<button type='button' className='btn btn-primary col-auto me-2'>
85+
{t('Import OSADL Information')}
86+
</button>
87+
<button type='button' className='btn btn-danger col-auto me-2'>
88+
{t('Delete all License Information')}
89+
</button>
90+
</div>
91+
<div className='col-lg-4 d-flex justify-content-end buttonheader-title'>
92+
{t('License Administration')}
93+
</div>
94+
</div>
95+
<div className='mt-4'>
96+
<h5
97+
style={{
98+
color: '#5D8EA9',
99+
borderBottom: '1px solid #5D8EA9',
100+
fontSize: '1rem',
101+
fontWeight: 'bold',
102+
textTransform: 'uppercase',
103+
}}
104+
>
105+
{t('Upload License Archive')}
106+
</h5>
107+
<ToastContainer position='top-start'>
108+
<ToastMessage
109+
show={toastData.show}
110+
type={toastData.type}
111+
message={toastData.message}
112+
contextual={toastData.contextual}
113+
onClose={() => setToastData({ ...toastData, show: false })}
114+
setShowToast={setToastData}
115+
/>
116+
</ToastContainer>
117+
<input type='file' onChange={handleFileChange} placeholder={t('Drop a File Here')} />
118+
<div className='form-check mt-3'>
119+
<input
120+
id='overWriteIfExternalIdsMatch'
121+
type='checkbox'
122+
className='form-check-input'
123+
name='overWriteIfExternalIdsMatch'
124+
/>
125+
<label className='form-check-label fw-bold fs-6' htmlFor='overWriteIfExternalIdsMatch'>
126+
{t('Overwrite if external ids match')}
127+
</label>
128+
</div>
129+
<div className='form-check'>
130+
<input
131+
id='overWriteIfIdsMatch'
132+
type='checkbox'
133+
className='form-check-input'
134+
name='overWriteIfIdsMatch'
135+
/>
136+
<label className='form-check-label fw-bold' htmlFor='overWriteIfIdsMatch'>
137+
{t('Overwrite if ids match')}
138+
</label>
139+
</div>
140+
<button type='button' className='btn btn-secondary col-auto mt-3' onClick={uploadLicenses}>
141+
{t('Upload Licenses')}
142+
</button>
143+
</div>
144+
</div>
145+
</>
146+
)
147+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (C) Siemens AG, 2023. Part of the SW360 Frontend Project.
2+
3+
// This program and the accompanying materials are made
4+
// available under the terms of the Eclipse Public License 2.0
5+
// which is available at https://www.eclipse.org/legal/epl-2.0/
6+
7+
// SPDX-License-Identifier: EPL-2.0
8+
// License-Filename: LICENSE
9+
10+
import { Metadata } from 'next'
11+
import LicenseAdministration from './components/LicenseAdministration'
12+
13+
export const metadata: Metadata = {
14+
title: 'Admin',
15+
}
16+
17+
async function LicenseAdministrationPage() {
18+
return <LicenseAdministration />
19+
}
20+
21+
export default LicenseAdministrationPage

src/components/sw360/Navbar/Navbar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function Navbar() {
4646
{ href: '#', name: t('User'), id: 'admin_user' },
4747
{ href: '/admin/vendors', name: t('Vendors'), id: 'admin_vendors' },
4848
{ href: '#', name: t('Bulk Release Edit'), id: 'admin_bulk_edit' },
49-
{ href: '#', name: t('Licenses'), id: 'admin_licenses' },
49+
{ href: '/admin/licenses', name: t('Licenses'), id: 'admin_licenses' },
5050
{ href: '#', name: t('Obligations'), id: 'admin_obligations' },
5151
{ href: '#', name: t('Schedule'), id: 'admin_schedule' },
5252
{ href: '#', name: t('Fossology'), id: 'admin_fossology' },

0 commit comments

Comments
 (0)