Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

53 profile not working correctly #54

Merged
merged 2 commits into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/thick-lizards-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@metalizzsas/nuster-turbine-machines": patch
"@metalizzsas/nuster-typings": patch
"@metalizzsas/nuster-turbine": patch
---

Migrated from id to \_id on mongoose documents
6 changes: 6 additions & 0 deletions .changeset/unlucky-cows-battle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@metalizzsas/nuster-desktop": patch
"@metalizzsas/nuster-turbine": patch
---

Made profiles work again
12 changes: 6 additions & 6 deletions libs/turbine-machines/data/metalfog/m/1/specs.json
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@
"profilePremades": [
{
"skeleton": "default",
"id": "premade_usl",
"_id": "premade_usl",
"name": "usl",
"isPremade": true,
"isRemovable": false,
Expand Down Expand Up @@ -721,7 +721,7 @@
},
{
"skeleton": "default",
"id": "premade_usl-retake",
"_id": "premade_usl-retake",
"name": "usl-retake",
"isPremade": true,
"isRemovable": false,
Expand Down Expand Up @@ -756,7 +756,7 @@
},
{
"skeleton": "default",
"id": "premade_usl-activation-porous",
"_id": "premade_usl-activation-porous",
"name": "usl-activation-porous",
"isPremade": true,
"isRemovable": false,
Expand Down Expand Up @@ -4999,7 +4999,7 @@
"content": [
{
"skeleton": "default",
"id": "premade_cem",
"_id": "premade_cem",
"name": "cem",
"isPremade": true,
"isRemovable": false,
Expand Down Expand Up @@ -5034,7 +5034,7 @@
},
{
"skeleton": "default",
"id": "premade_cem-retake",
"_id": "premade_cem-retake",
"name": "cem-retake",
"isPremade": true,
"isRemovable": false,
Expand Down Expand Up @@ -5096,7 +5096,7 @@
"content": [
{
"skeleton": "default",
"id": "premade_llc",
"_id": "premade_llc",
"name": "llc",
"isPremade": true,
"isRemovable": false,
Expand Down
6 changes: 3 additions & 3 deletions libs/turbine-machines/data/smoothit/m/1/specs.json
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@
"profilePremades": [
{
"skeleton": "default",
"id": "premade_fdm",
"_id": "premade_fdm",
"name": "fdm",
"isPremade": true,
"isRemovable": false,
Expand Down Expand Up @@ -454,7 +454,7 @@
},
{
"skeleton": "default",
"id": "premade_sls",
"_id": "premade_sls",
"name": "sls",
"isPremade": true,
"isRemovable": false,
Expand Down Expand Up @@ -484,7 +484,7 @@
},
{
"skeleton": "default",
"id": "premade_sla",
"_id": "premade_sla",
"name": "sla",
"isPremade": true,
"isRemovable": false,
Expand Down
6 changes: 3 additions & 3 deletions libs/turbine-machines/data/smoothit/m/2/specs.json
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@
"profilePremades": [
{
"skeleton": "default",
"id": "premade_fdm",
"_id": "premade_fdm",
"name": "fdm",
"isPremade": true,
"isOverwritable": false,
Expand Down Expand Up @@ -449,7 +449,7 @@
},
{
"skeleton": "default",
"id": "premade_sls",
"_id": "premade_sls",
"name": "sls",
"isPremade": true,
"isOverwritable": false,
Expand Down Expand Up @@ -479,7 +479,7 @@
},
{
"skeleton": "default",
"id": "premade_sla",
"_id": "premade_sla",
"name": "sla",
"isPremade": true,
"isOverwritable": false,
Expand Down
4 changes: 2 additions & 2 deletions libs/turbine-machines/data/uscleaner/m/1/specs.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
"profilePremades": [
{
"skeleton": "default",
"id": "premade_5min",
"_id": "premade_5min",
"name": "5min30deg",
"isPremade": true,
"isRemovable": false,
Expand Down Expand Up @@ -435,7 +435,7 @@
"content": [
{
"skeleton": "default",
"id": "premade_10min30deg",
"_id": "premade_10min30deg",
"name": "10min30deg",
"isRemovable": false,
"isOverwritable": false,
Expand Down
4 changes: 2 additions & 2 deletions libs/typings/src/hydrated/profile/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IProfileConfig, ProfileSkeletonFields } from "../../spec/profile";

export type IProfileHydrated = Omit<IProfileConfig, "values" | "id"> & { id?: string, modificationDate: number, values: ProfileSkeletonFields[] };
export type IProfileHydrated = Omit<IProfileConfig, "values"> & { modificationDate: number, values: ProfileSkeletonFields[] };

export type IProfileStored = Omit<IProfileConfig, "id"> & { id?: string, modificationDate: number };
export type IProfileStored = IProfileConfig & { modificationDate: number };
2 changes: 1 addition & 1 deletion libs/typings/src/spec/profile/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export interface IProfileConfig {
name: string;

/** Premade profile have id */
id?: string;
_id?: string;

/** Name of the referencing skeleton profile */
skeleton: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import Navcontainertitle from '../navigation/navcontainertitle.svelte';
import { layoutSimplified } from '$lib/utils/stores/settings';

const prepareCycle = (cycleType: string, profileID: string) => {
void fetch(`//${$Linker}/api/v1/cycle/${cycleType}/${profileID}`, {
const prepareCycle = (cycleType: string, profileID: string | undefined) => {
void fetch(`//${$Linker}/api/v1/cycle/${cycleType}/${profileID != undefined ? profileID : ''}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand Down Expand Up @@ -73,7 +73,7 @@
{#each $machineData.profiles.filter((p) => p.skeleton == ct.name && p.isPremade != true) as p}
<div
class="bg-indigo-500 text-white p-2 flex flex-col items-center justify-center rounded-xl transition-all font-semibold"
on:click={() => prepareCycle(ct.name, p.id)}
on:click={() => prepareCycle(ct.name, p._id)}
>
<div
class="flex flex-row gap-4 items-center justify-items-start w-full"
Expand Down
18 changes: 9 additions & 9 deletions packages/desktop/src/lib/components/cycle/quickstart.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
let saveProfileNameInvalid = false;
let deleteProfileModalShown = false;

$: $profile = profiles.find((k) => k.id == selectedProfile);
$: $profile = profiles.find((k) => k._id == selectedProfile);
$: if ($machineData.cycle !== undefined) void goto('/app/cycle');
$: if (saveProfileNameInvalid == true) {
setTimeout(() => (saveProfileNameInvalid = false), 5000);
Expand All @@ -51,7 +51,7 @@
const defaultProfile: IProfileHydrated = {

skeleton: "default",
id: "skeleton",
_id: "skeleton",
name: "—",

isRemovable: false,
Expand All @@ -66,11 +66,11 @@

const saveProfile = async (name?: string) => {
if ($profile !== undefined) {
const newp = $profile.id == 'skeleton';
const newp = $profile._id == 'skeleton';

if (name) $profile.name = name;

if (newp) $profile.id = 'created';
if (newp) $profile._id = 'created';

await fetch('//' + $Linker + '/api/v1/profiles' + (newp ? '/create' : ''), {
method: newp ? 'PUT' : 'POST',
Expand All @@ -85,7 +85,7 @@

const deleteProfile = async () => {
if ($profile !== undefined) {
await fetch(`//${$Linker}/api/v1/profiles/${$profile.id || ''}`, {
await fetch(`//${$Linker}/api/v1/profiles/${$profile._id || ''}`, {
method: 'DELETE',
});

Expand All @@ -95,11 +95,11 @@

const quickStart = async () => {
if ($profile !== undefined) {
const QSProfile = $profile.id == 'skeleton';
const QSProfile = $profile._id == 'skeleton';

if (QSProfile) $profile.name = 'Quickstart';

const url = `//${$Linker}/api/v1/cycle/default/${(QSProfile ? '' : ($profile.id || ''))}`;
const url = `//${$Linker}/api/v1/cycle/default/${(QSProfile ? '' : ($profile._id || ''))}`;
const body = QSProfile ? JSON.stringify(profile) : '';

const startRequest = await fetch(url, {
Expand Down Expand Up @@ -201,7 +201,7 @@
bind:value={selectedProfile}
>
{#each profiles.sort((a, b) => (a.name < b.name ? 1 : -1)) as profileListElement}
<option value={profileListElement.id}>
<option value={profileListElement._id}>
{profileListElement.isPremade
? $_('cycle.types.' + profileListElement.name)
: profileListElement.name}
Expand All @@ -212,7 +212,7 @@
<button
class="self-center bg-emerald-500 text-white p-2 rounded-full"
on:click|stopPropagation={() => {
if ($profile && $profile.id == 'skeleton') {
if ($profile && $profile._id == 'skeleton') {
saveProfileModalShown = true;
} else {
void saveProfile();
Expand Down
63 changes: 31 additions & 32 deletions packages/desktop/src/lib/components/profile/profile.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import { goto } from '$app/navigation';
import { Linker } from '$lib/utils/stores/linker';
import type { IProfileHydrated } from '@metalizzsas/nuster-typings/build/hydrated/profile';
import { translateProfileName } from './profiletranslation';

export let profile: IProfileHydrated;
export let delCb: () => void;
Expand All @@ -13,42 +14,43 @@
let deleteProfileModalShown = false;

const copyProfile = (newName: string) => {
let newProfile = profile;

newProfile.id = 'copied';
newProfile.name = newName;

fetch('//' + $Linker + '/api/v1/profiles/', {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(newProfile),
}).then((returnData) => {
returnData.json().then((result: IProfileHydrated) => {
void goto(`/app/profiles/${result.id || ''}`);
if(newName.length > 1)
{
let newProfile = profile;

newProfile._id = 'copied';
newProfile.name = newName;

fetch('//' + $Linker + '/api/v1/profiles/', {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(newProfile),
}).then((returnData) => {
returnData.json().then((result: IProfileHydrated) => {
void goto(`/app/profiles/${result._id || ''}`);
}).catch(() => {
console.error("Failed to convert json for copied profile");
})
}).catch(() => {
console.error("Failed to convert json for copied profile");
console.error("Failed to copy profile");
})
}).catch(() => {
console.error("Failed to copy profile");
})
}
}

const deleteProfile = (profile: IProfileHydrated) => {
fetch(`//${$Linker}/api/v1/profiles/${profile.id ?? ''}`, {
fetch(`//${$Linker}/api/v1/profiles/${profile._id ?? ''}`, {
method: 'DELETE',
}).then(() => delCb()).catch(() => {console.error("Failed to delete profile")});
}
</script>

<ModalPrompt
bind:shown={copyProfileModalShown}
title={$_('profile.modals.copy.title').replace(
'{profile.name}',
profile.isPremade ? $_('cycle.types.' + profile.name) : profile.name,
)}
placeholder={profile.isPremade ? $_('cycle.types.' + profile.name) : profile.name}
title={translateProfileName($_, profile)}
placeholder={translateProfileName($_, profile)}
buttons={[
{
text: $_('ok'),
Expand All @@ -63,16 +65,13 @@
>
{$_('profile.modals.copy.message').replace(
'{profile.name}',
profile.isPremade ? $_('cycle.types.' + profile.name) : profile.name,
translateProfileName($_, profile),
)}
</ModalPrompt>

<Modal
bind:shown={deleteProfileModalShown}
title={$_('profile.modals.delete.title').replace(
'{profile.name}',
profile.isPremade ? $_('cycle.types.' + profile.name) : profile.name,
)}
title={translateProfileName($_, profile)}
buttons={[
{
text: $_('yes'),
Expand All @@ -87,17 +86,17 @@
>
{$_('profile.modals.delete.message').replace(
'{profile.name}',
profile.isPremade ? $_('cycle.types.' + profile.name) : profile.name,
translateProfileName($_, profile),
)}
</Modal>

<div
class="bg-zinc-700 text-white py-2 px-4 rounded-2xl flex flex-row justify-between cursor-pointer"
on:click={() => goto(`profiles/${profile.id || ''}`)}
on:click={() => goto(`profiles/${profile._id || ''}`)}
>
<div class="flex flex-col">
<span class="text-md font-semibold">
{profile.isPremade === true ? $_('cycle.types.' + profile.name) : profile.name}
{translateProfileName($_, profile)}
</span>
<span class="text-xs text-gray-300 italic">
{$_('profile.modification-date')}: {$date(new Date(profile.modificationDate), {
Expand All @@ -109,7 +108,7 @@
</span>
</div>
<div class="flex flex-row gap-4 self-center">
{#if profile.isRemovable !== undefined}
{#if profile.isRemovable !== false}
<button
class="self-center bg-red-500 text-white p-2 rounded-full"
on:click|stopPropagation={() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
{#if enabledCategoryField !== undefined}
<Toggle
bind:value={enabledCategoryField.value}
locked={!profile.isOverwritable}
enableGrayScale={!profile.isOverwritable}
locked={profile.isOverwritable === false}
enableGrayScale={profile.isOverwritable === false}
on:change={(e) => { if(enabledCategoryField) { enabledCategoryField.value = e.detail.value } }}
/>
{/if}
Expand Down
Loading