Skip to content

Commit

Permalink
Merge pull request #132 from ghackenberg/edt
Browse files Browse the repository at this point in the history
Edt
  • Loading branch information
ghackenberg authored Dec 20, 2024
2 parents 0e6c09d + 449e6f5 commit 95c7de9
Show file tree
Hide file tree
Showing 16 changed files with 1,717 additions and 154 deletions.
Binary file added packages/frontend/src/images/blank.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/frontend/src/images/edit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions packages/frontend/src/scripts/clients/rest/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import { VersionCreate, VersionREST, VersionRead, VersionUpdate } from 'productb
import { auth } from '../auth'
import { CacheAPI } from '../cache'

class VersionClientImpl implements VersionREST<VersionCreate, VersionUpdate, File, Blob> {
class VersionClientImpl implements VersionREST<VersionCreate, VersionUpdate, Blob, Blob> {
async findVersions(productId: string): Promise<VersionRead[]> {
return (await axios.get<VersionRead[]>(`/rest/products/${productId}/versions`, auth)).data
}
async addVersion(productId: string, data: VersionCreate, files: {model: File, image: Blob}): Promise<VersionRead> {
async addVersion(productId: string, data: VersionCreate, files: {model: Blob, image: Blob}): Promise<VersionRead> {
const body = new FormData()
body.append('data', JSON.stringify(data))
if (files.model) {
body.append('model', files.model)
body.append('model', files.model, files.model.type == 'application/x-ldraw' && 'model.ldr')
}
if (files.image) {
body.append('image', files.image)
Expand All @@ -25,7 +25,7 @@ class VersionClientImpl implements VersionREST<VersionCreate, VersionUpdate, Fil
async getVersion(productId: string, versionId: string): Promise<VersionRead> {
return (await axios.get<VersionRead>(`/rest/products/${productId}/versions/${versionId}`, auth)).data
}
async updateVersion(productId: string, versionId: string, data: VersionUpdate, files?: {model: File, image: Blob}): Promise<VersionRead> {
async updateVersion(productId: string, versionId: string, data: VersionUpdate, files?: {model: Blob, image: Blob}): Promise<VersionRead> {
const body = new FormData()
body.append('data', JSON.stringify(data))
if (files) {
Expand Down
2 changes: 2 additions & 0 deletions packages/frontend/src/scripts/components/routers/Product.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { ProductMilestoneIssueSettingView } from '../views/ProductMilestoneIssue
import { ProductMilestoneSettingView } from '../views/ProductMilestoneSetting'
import { ProductSettingView } from '../views/ProductSetting'
import { ProductVersionView } from '../views/ProductVersion'
import { ProductVersionEditorView } from '../views/ProductVersionEditor'
import { ProductVersionSettingView } from '../views/ProductVersionSetting'

const ProductRouter = () => {
Expand All @@ -40,6 +41,7 @@ const ProductRouter = () => {
<Redirect path="/products/:productId/issues/:issueId" to="/products/:productId/issues/:issueId/comments" push={false}/>
<Route path="/products/:productId/issues" component={ProductIssueView}/>

<Route path="/products/:productId/versions/:versionId/editor" component={ProductVersionEditorView}/>
<Route path="/products/:productId/versions/:versionId/settings" component={ProductVersionSettingView}/>
<Redirect path="/products/:productId/versions/:versionId" to="/products/:productId/versions/:versionId/settings" push={false}/>
<Route path="/products/:productId/versions" component={ProductVersionView}/>
Expand Down
43 changes: 27 additions & 16 deletions packages/frontend/src/scripts/components/views/ProductVersion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import { ProductView3D } from '../widgets/ProductView3D'
import { LoadingView } from './Loading'

import LoadIcon from '/src/images/load.png'
import EditIcon from '/src/images/setting.png'
import ForkIcon from '/src/images/app.png'
import DownloadIcon from '/src/images/download.png'
import VersionIcon from '/src/images/version.png'
import PartIcon from '/src/images/part.png'
Expand Down Expand Up @@ -69,16 +71,12 @@ export const ProductVersionView = () => {

// FUNCTIONS

async function onClick(event: React.MouseEvent<HTMLDivElement>, version: VersionRead) {
if (event.ctrlKey) {
await push(`/products/${productId}/versions/${version.versionId}/settings`)
} else {
// Set context model
setContextVersion(version)
// Switch to model view on small screens
if (window.getComputedStyle(ref.current).display == 'none') {
await push('#model')
}
async function onClick(_event: React.MouseEvent<HTMLDivElement>, version: VersionRead) {
// Set context model
setContextVersion(version)
// Switch to model view on small screens
if (window.getComputedStyle(ref.current).display == 'none') {
await push('#model')
}
}

Expand All @@ -102,9 +100,14 @@ export const ProductVersionView = () => {
<div className='header'>
{contextUser ? (
contextUser.admin || members.filter(member => member.userId == contextUser.userId && member.role != 'customer').length == 1 ? (
<NavLink to={`/products/${productId}/versions/new/settings`} className='button green fill'>
<strong>New</strong> version
</NavLink>
<>
<NavLink to={`/products/${productId}/versions/new/settings`} className='button green fill'>
<strong>Upload</strong> version
</NavLink>
<NavLink to={`/products/${productId}/versions/new/editor`} className='button green stroke'>
<strong>Create</strong> version (beta)
</NavLink>
</>
) : (
<a className='button green fill'>
<strong>New</strong> version <span className='badge'>requires role</span>
Expand Down Expand Up @@ -247,9 +250,17 @@ export const ProductVersionView = () => {
</div>
<div className="text">
<div>
<a className="download" title="Download model" href={`/rest/files/${curVers.versionId}.${curVers.modelType}`}>
<img src={DownloadIcon}/>
</a>
<span className='actions'>
<NavLink title="Edit settings" to={`/products/${productId}/versions/${curVers.versionId}/settings`}>
<img src={EditIcon}/>
</NavLink>
<NavLink title="Edit model" to={`/products/${productId}/versions/${curVers.versionId}/editor`}>
<img src={ForkIcon}/>
</NavLink>
<a title="Download model" href={`/rest/files/${curVers.versionId}.${curVers.modelType}`}>
<img src={DownloadIcon}/>
</a>
</span>
<span className="label" style={{backgroundColor: hsl(color[curVers.versionId])}}>
{curVers.major}.{curVers.minor}.{curVers.patch}
</span>
Expand Down
Loading

0 comments on commit 95c7de9

Please sign in to comment.