Skip to content

Commit

Permalink
Merge pull request #182 from siemens/admin_licenses
Browse files Browse the repository at this point in the history
feat(admin_licenses): Add functionality to upload license archive
  • Loading branch information
heliocastro authored Dec 7, 2023
2 parents e6fa710 + f484df7 commit 0c2898f
Show file tree
Hide file tree
Showing 9 changed files with 230 additions and 7 deletions.
13 changes: 12 additions & 1 deletion messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,17 @@
"Creator Group": "Creator Group",
"ECC Assessor": "ECC Assessor",
"ECC Assessor Group": "ECC Assessor Group",
"ECC Assessment Date": "ECC Assessment Date"
"ECC Assessment Date": "ECC Assessment Date",
"License Administration": "License Administration",
"Download License Archive": "Download License Archive",
"Import SPDX Information": "Import SPDX Information",
"Import OSADL Information": "Import OSADL Information",
"Delete all License Information": "Delete all License Information",
"Upload License Archive": "Upload License Archive",
"Upload Licenses": "Upload Licenses",
"Overwrite if external ids match": "Overwrite if external ids match",
"Overwrite if ids match": "Overwrite if ids match",
"Licenses uploaded successfully": "Licenses uploaded successfully",
"Please select a file": "Please select a file!"
}
}
13 changes: 12 additions & 1 deletion messages/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,17 @@
"Creator Group": "Creator Group",
"ECC Assessor": "ECC Assessor",
"ECC Assessor Group": "ECC Assessor Group",
"ECC Assessment Date": "ECC Assessment Date"
"ECC Assessment Date": "ECC Assessment Date",
"License Administration": "License Administration",
"Download License Archive": "Download License Archive",
"Import SPDX Information": "Import SPDX Information",
"Import OSADL Information": "Import OSADL Information",
"Delete all License Information": "Delete all License Information",
"Upload License Archive": "Upload License Archive",
"Upload Licenses": "Upload Licenses",
"Overwrite if external ids match": "Overwrite if external ids match",
"Overwrite if ids match": "Overwrite if ids match",
"Licenses uploaded successfully": "Licenses uploaded successfully",
"Please select a file": "Please select a file!"
}
}
13 changes: 12 additions & 1 deletion messages/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,17 @@
"Creator Group": "Creator Group",
"ECC Assessor": "ECC Assessor",
"ECC Assessor Group": "ECC Assessor Group",
"ECC Assessment Date": "ECC Assessment Date"
"ECC Assessment Date": "ECC Assessment Date",
"License Administration": "License Administration",
"Download License Archive": "Download License Archive",
"Import SPDX Information": "Import SPDX Information",
"Import OSADL Information": "Import OSADL Information",
"Delete all License Information": "Delete all License Information",
"Upload License Archive": "Upload License Archive",
"Upload Licenses": "Upload Licenses",
"Overwrite if external ids match": "Overwrite if external ids match",
"Overwrite if ids match": "Overwrite if ids match",
"Licenses uploaded successfully": "Licenses uploaded successfully",
"Please select a file": "Please select a file!"
}
}
13 changes: 12 additions & 1 deletion messages/vi.json
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,17 @@
"Creator Group": "Creator Group",
"ECC Assessor": "ECC Assessor",
"ECC Assessor Group": "ECC Assessor Group",
"ECC Assessment Date": "ECC Assessment Date"
"ECC Assessment Date": "ECC Assessment Date",
"License Administration": "License Administration",
"Download License Archive": "Download License Archive",
"Import SPDX Information": "Import SPDX Information",
"Import OSADL Information": "Import OSADL Information",
"Delete all License Information": "Delete all License Information",
"Upload License Archive": "Upload License Archive",
"Upload Licenses": "Upload Licenses",
"Overwrite if external ids match": "Overwrite if external ids match",
"Overwrite if ids match": "Overwrite if ids match",
"Licenses uploaded successfully": "Licenses uploaded successfully",
"Please select a file": "Please select a file!"
}
}
13 changes: 12 additions & 1 deletion messages/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,17 @@
"Creator Group": "Creator Group",
"ECC Assessor": "ECC Assessor",
"ECC Assessor Group": "ECC Assessor Group",
"ECC Assessment Date": "ECC Assessment Date"
"ECC Assessment Date": "ECC Assessment Date",
"License Administration": "License Administration",
"Download License Archive": "Download License Archive",
"Import SPDX Information": "Import SPDX Information",
"Import OSADL Information": "Import OSADL Information",
"Delete all License Information": "Delete all License Information",
"Upload License Archive": "Upload License Archive",
"Upload Licenses": "Upload Licenses",
"Overwrite if external ids match": "Overwrite if external ids match",
"Overwrite if ids match": "Overwrite if ids match",
"Licenses uploaded successfully": "Licenses uploaded successfully",
"Please select a file": "Please select a file!"
}
}
2 changes: 1 addition & 1 deletion src/app/[locale]/admin/components/Admin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const AdminMainPage = () => {
<FiEdit2 /> {t('Bulk Release Edit')}
</button>
</Link>
<Link href='#'>
<Link href='/admin/licenses'>
<button type='button' className='btn btn-secondary mb-2 mx-2' style={{ width: '210px' }}>
<BsFileEarmarkText /> {t('Licenses')}
</button>
Expand Down
147 changes: 147 additions & 0 deletions src/app/[locale]/admin/licenses/components/LicenseAdministration.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
// Copyright (C) Siemens AG, 2023. Part of the SW360 Frontend Project.

// This program and the accompanying materials are made
// available under the terms of the Eclipse Public License 2.0
// which is available at https://www.eclipse.org/legal/epl-2.0/

// SPDX-License-Identifier: EPL-2.0
// License-Filename: LICENSE

'use client'

import { HttpStatus, ToastData } from '@/object-types'
import { ApiUtils } from '@/utils'
import { getSession, signIn } from 'next-auth/react'
import { useTranslations } from 'next-intl'
import { ToastMessage } from 'next-sw360'
import { useRef, useState } from 'react'
import { ToastContainer } from 'react-bootstrap'

export default function AddVendor() {
const t = useTranslations('default')
const file = useRef<File | undefined>()

const [toastData, setToastData] = useState<ToastData>({
show: false,
type: '',
message: '',
contextual: '',
})

const alert = (show_data: boolean, status_type: string, message: string, contextual: string) => {
setToastData({
show: show_data,
type: status_type,
message: message,
contextual: contextual,
})
}

const handleFileChange = (e: React.ChangeEvent<HTMLInputElement>) => {
if (!e.currentTarget.files && e.currentTarget.files.length === 0) {
return
}
file.current = e.currentTarget.files[0]
}

const uploadLicenses = async () => {
try {
if (!file.current) {
alert(true, 'Error', t('Please select a file'), 'danger')
return
}
const formData = new FormData()
formData.append('licenseFile', file.current, file.current.name)

const session = await getSession()

const response = await ApiUtils.POST('licenses/upload', formData, session.user.access_token)
if (response.status === HttpStatus.UNAUTHORIZED) {
signIn()
} else if (response.status === HttpStatus.OK) {
alert(true, 'Success', t('Licenses uploaded successfully'), 'success')
} else {
const data = await response.json()
console.log(data)
alert(true, 'Error', t('Something went wrong'), 'danger')
}
} catch (err) {
console.error(err)
}
}

return (
<>
<div className='mt-4 mx-5'>
<div className='row'>
<div className='col-lg-8'>
<button type='button' className='btn btn-primary col-auto me-2'>
{t('Download License Archive')}
</button>
<button type='button' className='btn btn-primary col-auto me-2'>
{t('Import SPDX Information')}
</button>
<button type='button' className='btn btn-primary col-auto me-2'>
{t('Import OSADL Information')}
</button>
<button type='button' className='btn btn-danger col-auto me-2'>
{t('Delete all License Information')}
</button>
</div>
<div className='col-lg-4 d-flex justify-content-end buttonheader-title'>
{t('License Administration')}
</div>
</div>
<div className='mt-4'>
<h5
style={{
color: '#5D8EA9',
borderBottom: '1px solid #5D8EA9',
fontSize: '1rem',
fontWeight: 'bold',
textTransform: 'uppercase',
}}
>
{t('Upload License Archive')}
</h5>
<ToastContainer position='top-start'>
<ToastMessage
show={toastData.show}
type={toastData.type}
message={toastData.message}
contextual={toastData.contextual}
onClose={() => setToastData({ ...toastData, show: false })}
setShowToast={setToastData}
/>
</ToastContainer>
<input type='file' onChange={handleFileChange} placeholder={t('Drop a File Here')} />
<div className='form-check mt-3'>
<input
id='overWriteIfExternalIdsMatch'
type='checkbox'
className='form-check-input'
name='overWriteIfExternalIdsMatch'
/>
<label className='form-check-label fw-bold fs-6' htmlFor='overWriteIfExternalIdsMatch'>
{t('Overwrite if external ids match')}
</label>
</div>
<div className='form-check'>
<input
id='overWriteIfIdsMatch'
type='checkbox'
className='form-check-input'
name='overWriteIfIdsMatch'
/>
<label className='form-check-label fw-bold' htmlFor='overWriteIfIdsMatch'>
{t('Overwrite if ids match')}
</label>
</div>
<button type='button' className='btn btn-secondary col-auto mt-3' onClick={uploadLicenses}>
{t('Upload Licenses')}
</button>
</div>
</div>
</>
)
}
21 changes: 21 additions & 0 deletions src/app/[locale]/admin/licenses/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (C) Siemens AG, 2023. Part of the SW360 Frontend Project.

// This program and the accompanying materials are made
// available under the terms of the Eclipse Public License 2.0
// which is available at https://www.eclipse.org/legal/epl-2.0/

// SPDX-License-Identifier: EPL-2.0
// License-Filename: LICENSE

import { Metadata } from 'next'
import LicenseAdministration from './components/LicenseAdministration'

export const metadata: Metadata = {
title: 'Admin',
}

async function LicenseAdministrationPage() {
return <LicenseAdministration />
}

export default LicenseAdministrationPage
2 changes: 1 addition & 1 deletion src/components/sw360/Navbar/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function Navbar() {
{ href: '#', name: t('User'), id: 'admin_user' },
{ href: '/admin/vendors', name: t('Vendors'), id: 'admin_vendors' },
{ href: '#', name: t('Bulk Release Edit'), id: 'admin_bulk_edit' },
{ href: '#', name: t('Licenses'), id: 'admin_licenses' },
{ href: '/admin/licenses', name: t('Licenses'), id: 'admin_licenses' },
{ href: '#', name: t('Obligations'), id: 'admin_obligations' },
{ href: '#', name: t('Schedule'), id: 'admin_schedule' },
{ href: '#', name: t('Fossology'), id: 'admin_fossology' },
Expand Down

0 comments on commit 0c2898f

Please sign in to comment.