-
Notifications
You must be signed in to change notification settings - Fork 235
Expand file tree
/
Copy path+page.svelte
More file actions
227 lines (212 loc) · 8.24 KB
/
+page.svelte
File metadata and controls
227 lines (212 loc) · 8.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
<script lang="ts">
import { sdk } from '$lib/stores/sdk';
import { onMount } from 'svelte';
import { toLocaleDateTime } from '$lib/helpers/date';
import { addNotification } from '$lib/stores/notifications';
import { project } from '../store';
import { services, type Service } from '$lib/stores/project-services';
import { CardGrid, CopyInput, Box, Heading } from '$lib/components';
import { Button, Form, FormList, InputText, InputSwitch } from '$lib/elements/forms';
import { Container } from '$lib/layout';
import { invalidate } from '$app/navigation';
import { Dependencies } from '$lib/constants';
import Delete from './deleteProject.svelte';
import { base } from '$app/paths';
import { page } from '$app/stores';
import { Submit, trackEvent, trackError } from '$lib/actions/analytics';
import EnableAllServices from './enableAllServices.svelte';
import DisableAllServices from './disableAllServices.svelte';
let name: string = null;
let showDelete = false;
const endpoint = sdk.forConsole.client.config.endpoint;
const projectId = $page.params.project;
let showDisableAll = false;
let showEnableAll = false;
onMount(async () => {
name ??= $project.name;
});
async function updateName() {
try {
await sdk.forConsole.projects.update($project.$id, name);
await invalidate(Dependencies.PROJECT);
addNotification({
type: 'success',
message: 'Project name has been updated'
});
trackEvent(Submit.ProjectUpdateName);
} catch (error) {
addNotification({
type: 'error',
message: error.message
});
trackError(error, Submit.ProjectUpdateName);
}
}
async function toggleAllServices(status: boolean) {
if (status && !showEnableAll) {
showEnableAll = true;
return;
}
if (!status && !showDisableAll) {
showDisableAll = true;
return;
}
try {
const path = '/projects/' + $project.$id + '/service/all';
await sdk.forConsole.client.call(
'PATCH',
new URL(sdk.forConsole.client.config.endpoint + path),
{
'content-type': 'application/json'
},
{
status: status
}
);
invalidate(Dependencies.PROJECT);
addNotification({
type: 'success',
message:
'All services for ' +
$project.name +
' has been ' +
(status ? 'enabled.' : 'disabled.')
});
trackEvent(Submit.ProjectService);
} catch (error) {
addNotification({
type: 'error',
message: error.message
});
trackError(error, Submit.ProjectService);
} finally {
showDisableAll = false;
showEnableAll = false;
}
}
$: {
// When project name is updated, finalize the updating flow
$project.name;
}
async function serviceUpdate(service: Service) {
try {
await sdk.forConsole.projects.updateServiceStatus(
$project.$id,
service.method,
service.value
);
await invalidate(Dependencies.PROJECT);
addNotification({
type: 'success',
message: `${service.label} service has been ${
service.value ? 'enabled' : 'disabled'
}`
});
trackEvent(Submit.ProjectService, {
method: service.method,
value: service.value
});
} catch (error) {
addNotification({
type: 'error',
message: error.message
});
trackError(error, Submit.ProjectService);
}
}
$: services.load($project);
</script>
<Container>
{#if $project}
<Form onSubmit={updateName}>
<CardGrid>
<Heading tag="h6" size="7">API Credentials</Heading>
<p class="text">Access Appwrite services using your API Endpoint and Project ID.</p>
<svelte:fragment slot="aside">
<FormList>
<CopyInput label="Project ID" showLabel={true} value={$project.$id} />
<CopyInput label="API Endpoint" showLabel={true} value={endpoint} />
</FormList>
</svelte:fragment>
<svelte:fragment slot="actions">
<Button
secondary
event="view_keys"
href={`${base}/console/project-${projectId}/overview/keys#integrations`}>
View API Keys
</Button>
</svelte:fragment>
</CardGrid>
<CardGrid>
<Heading tag="h6" size="7">Name</Heading>
<svelte:fragment slot="aside">
<FormList>
<InputText
id="name"
label="Name"
bind:value={name}
required
placeholder="Enter name" />
</FormList>
</svelte:fragment>
<svelte:fragment slot="actions">
<Button disabled={name === $project.name} submit>Update</Button>
</svelte:fragment>
</CardGrid>
</Form>
<CardGrid>
<Heading tag="h6" size="7">Services</Heading>
<p class="text">Choose services you wish to enable or disable.</p>
<svelte:fragment slot="aside">
<ul class="buttons-list u-main-end">
<li class="buttons-list-item">
<Button text={true} on:click={() => toggleAllServices(true)}
>Enable all</Button>
</li>
<li class="buttons-list-item">
<Button text={true} on:click={() => toggleAllServices(false)}
>Disable all</Button>
</li>
</ul>
<FormList>
<form class="form card-separator">
<ul class="form-list is-multiple">
{#each $services.list as service}
<InputSwitch
label={service.label}
id={service.method}
bind:value={service.value}
on:change={() => {
serviceUpdate(service);
}} />
{/each}
</ul>
</form>
</FormList>
</svelte:fragment>
</CardGrid>
<CardGrid danger>
<div>
<Heading tag="h6" size="7">Delete Project</Heading>
</div>
<p>
The project will be permanently deleted, including all the metadata, resources and
stats within it. This action is irreversible.
</p>
<svelte:fragment slot="aside">
<Box>
<svelte:fragment slot="title">
<h6 class="u-bold u-trim-1">{$project.name}</h6>
</svelte:fragment>
<p>Last update: {toLocaleDateTime($project.$updatedAt)}</p>
</Box>
</svelte:fragment>
<svelte:fragment slot="actions">
<Button secondary on:click={() => (showDelete = true)}>Delete</Button>
</svelte:fragment>
</CardGrid>
{/if}
</Container>
<Delete bind:showDelete />
<DisableAllServices handleDisableAll={() => toggleAllServices(false)} bind:show={showDisableAll} />
<EnableAllServices handleEnableAll={() => toggleAllServices(true)} bind:show={showEnableAll} />