|
1 | 1 | <script> |
2 | 2 | import { page } from '$app/stores'; |
| 3 | + import { nullifyEmptyStrings } from '$lib/common/component_utilities'; |
3 | 4 | import { |
4 | 5 | AlertError, |
5 | 6 | displayStandardErrorAlert, |
|
22 | 23 | let cacheDir = ''; |
23 | 24 | let cacheDirError = ''; |
24 | 25 |
|
25 | | - let cacheDirSet = false; |
26 | | -
|
27 | 26 | let settingsUpdatedMessage = ''; |
28 | 27 |
|
29 | 28 | function addSlurmAccount() { |
|
42 | 41 | errorAlert.hide(); |
43 | 42 | } |
44 | 43 | settingsUpdatedMessage = ''; |
| 44 | + slurmAccountsError = ''; |
| 45 | + cacheDirError = ''; |
45 | 46 | const headers = new Headers(); |
46 | 47 | headers.set('Content-Type', 'application/json'); |
47 | 48 | const payload = { |
48 | 49 | slurm_accounts: slurmAccounts |
49 | 50 | }; |
50 | | - if (cacheDirSet || cacheDir) { |
| 51 | + if ($page.data.runnerBackend === 'slurm') { |
51 | 52 | payload.cache_dir = cacheDir; |
52 | 53 | } |
53 | 54 | const response = await fetch(`/api/auth/current-user/settings`, { |
54 | 55 | method: 'PATCH', |
55 | 56 | credentials: 'include', |
56 | 57 | headers, |
57 | | - body: JSON.stringify(payload) |
| 58 | + body: JSON.stringify(nullifyEmptyStrings(payload)) |
58 | 59 | }); |
59 | 60 | const result = await response.json(); |
60 | 61 | if (response.ok) { |
|
88 | 89 | function initFields(settings) { |
89 | 90 | slurmAccounts = settings.slurm_accounts; |
90 | 91 | cacheDir = settings.cache_dir || ''; |
91 | | - cacheDirSet = !!settings.cache_dir; |
92 | 92 | } |
93 | 93 |
|
94 | 94 | onMount(() => { |
|
106 | 106 | {settings.slurm_user || '-'} |
107 | 107 | </div> |
108 | 108 | </div> |
| 109 | + <div class="row mb-3"> |
| 110 | + <label class="col-lg-2 col-sm-4 fw-bold" for="cache-dir">Cache dir</label> |
| 111 | + <div class="col-lg-6 col-sm-8"> |
| 112 | + <div class="input-group" class:has-validation={cacheDirError}> |
| 113 | + <input |
| 114 | + type="text" |
| 115 | + class="form-control" |
| 116 | + id="cache-dir" |
| 117 | + bind:value={cacheDir} |
| 118 | + class:is-invalid={cacheDirError} |
| 119 | + /> |
| 120 | + {#if cacheDirError} |
| 121 | + <div class="invalid-feedback">{cacheDirError}</div> |
| 122 | + {/if} |
| 123 | + </div> |
| 124 | + </div> |
| 125 | + </div> |
109 | 126 | {/if} |
110 | 127 | {#if $page.data.runnerBackend === 'slurm_ssh'} |
111 | 128 | <div class="row mb-4"> |
|
150 | 167 | </div> |
151 | 168 | </div> |
152 | 169 |
|
153 | | - <div class="row mb-3"> |
154 | | - <label class="col-lg-2 col-sm-4 fw-bold" for="cache-dir">Cache dir</label> |
155 | | - <div class="col-lg-6 col-sm-8"> |
156 | | - <div class="input-group" class:has-validation={cacheDirError}> |
157 | | - <input |
158 | | - type="text" |
159 | | - class="form-control" |
160 | | - id="cache-dir" |
161 | | - bind:value={cacheDir} |
162 | | - class:is-invalid={cacheDirError} |
163 | | - /> |
164 | | - {#if cacheDirError} |
165 | | - <div class="invalid-feedback">{cacheDirError}</div> |
166 | | - {/if} |
167 | | - </div> |
168 | | - </div> |
169 | | - </div> |
170 | | - |
171 | 170 | <div class="row"> |
172 | 171 | <div class="col"> |
173 | 172 | <div id="settingsUpdate-error" /> |
|
0 commit comments