feat(settings): add btn to toggle add project btn

This commit is contained in:
Diptesh Choudhuri 2023-01-25 05:00:31 +00:00
parent 3be80896bb
commit 974e4c39fa
4 changed files with 72 additions and 56 deletions

File diff suppressed because one or more lines are too long

Binary file not shown.

View File

@ -1,42 +1,51 @@
PetiteVue.createApp({
//$delimiters: ['${', '}'], // https://github.com/vuejs/petite-vue/pull/100
activeTab: defaultTab,
selectedTimezone: userTimeZone,
vibrantColorsEnabled: JSON.parse(localStorage.getItem('wakapi_vibrant_colors') || false),
get tzOptions() {
return [defaultTzOption, ...tzs.sort().map(tz => ({ value: tz, text: tz }))]
},
updateTab() {
this.activeTab = window.location.hash.slice(1) || defaultTab
},
isActive(tab) {
return this.activeTab === tab
},
confirmRegenerate() {
if (confirm('Are you sure?')) {
document.querySelector('#form-regenerate-summaries').submit()
}
},
confirmWakatimeImport() {
if (confirm('Are you sure? The import can not be undone.')) {
document.querySelector('#form-import-wakatime').submit()
}
},
confirmClearData() {
if (confirm('Are you sure? This can not be undone!')) {
document.querySelector('#form-clear-data').submit()
}
},
confirmDeleteAccount() {
if (confirm('Are you sure? This can not be undone!')) {
document.querySelector('#form-delete-user').submit()
}
},
onToggleVibrantColors() {
localStorage.setItem('wakapi_vibrant_colors', this.vibrantColorsEnabled)
},
mounted() {
this.updateTab()
window.addEventListener('hashchange', () => this.updateTab())
}
}).mount('#settings-page')
//$delimiters: ['${', '}'], // https://github.com/vuejs/petite-vue/pull/100
activeTab: defaultTab,
selectedTimezone: userTimeZone,
vibrantColorsEnabled: JSON.parse(
localStorage.getItem("wakapi_vibrant_colors"),
),
labels: {},
get tzOptions() {
return [
defaultTzOption,
...tzs.sort().map((tz) => ({ value: tz, text: tz })),
];
},
updateTab() {
this.activeTab = window.location.hash.slice(1) || defaultTab;
},
isActive(tab) {
return this.activeTab === tab;
},
confirmRegenerate() {
if (confirm("Are you sure?")) {
document.querySelector("#form-regenerate-summaries").submit();
}
},
confirmWakatimeImport() {
if (confirm("Are you sure? The import can not be undone.")) {
document.querySelector("#form-import-wakatime").submit();
}
},
confirmClearData() {
if (confirm("Are you sure? This can not be undone!")) {
document.querySelector("#form-clear-data").submit();
}
},
confirmDeleteAccount() {
if (confirm("Are you sure? This can not be undone!")) {
document.querySelector("#form-delete-user").submit();
}
},
onToggleVibrantColors() {
localStorage.setItem("wakapi_vibrant_colors", this.vibrantColorsEnabled);
},
showProjectAddButton(index) {
this.labels[index] = true;
},
mounted() {
this.updateTab();
window.addEventListener("hashchange", () => this.updateTab());
},
}).mount("#settings-page");

View File

@ -186,7 +186,7 @@
style="line-height: 1.8">
&#9656;&nbsp; All <span class="font-semibold">{{ $alias.Type | typeName }}s</span> named
{{ range $j, $value := $alias.Values }}
<span class="text-white chip text-green-700">{{- $value -}}</span>
<span class="chip text-green-700">{{- $value -}}</span>
{{ if lt $j (add (len $alias.Values) -2) }}
<span class="-ml-1">{{- ", " | capitalize -}}</span>
{{ else if lt $j (add (len $alias.Values) -1) }}
@ -194,7 +194,7 @@
{{ end }}
{{ end }}
are mapped to <span class="font-semibold">{{ $alias.Type | typeName }}</span> <span
class="text-white chip text-green-700">{{ $alias.Key }}</span>
class="chip text-green-700">{{ $alias.Key }}</span>
</div>
<form class="float-right" action="" method="post">
<input type="hidden" name="action" value="delete_alias">
@ -255,7 +255,7 @@
<div class="mb-8">
<h3 class="inline-block font-semibold text-gray-300">Your labels</h3>
{{ range $i, $label := .Labels }}
<div class="flex items-center">
<div class="flex items-center" data-element-type="label">
<div class="text-gray-500 border-1 w-full border-green-700 inline-block my-1 py-1 text-align text-sm"
style="line-height: 1.8">
&#9656;&nbsp;&nbsp;<span class="font-semibold text-gray-300">{{ $label.Key }}:</span>
@ -268,18 +268,25 @@
<button type="submit" class="bg-gray-900 text-center hover:bg-gray-700 rounded-full w-4 h-4 leading-none text-red-600" title="Delete label">x</button>
</form>
{{ end }}
<form action="" method="post" class="inline-flex space-x-1">
<input type="hidden" name="action" class="block" value="add_label">
<input type="hidden" name="value" value="{{ $label.Key }}">
<select name="key" class="block text-sm select-default !w-auto">
{{ range $k, $project := $.Projects }}
<option value="{{ $project }}">{{ $project }}</option>
{{ end }}
</select>
<button type="submit" class="btn-primary btn-small">
Add project
<div class="ml-3 inline">
<button @click="showProjectAddButton({{ $i }})" class="top-1 relative" v-show="!labels[{{ $i }}]">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-4 h-4 text-gray-400">
<path stroke-linecap="round" stroke-linejoin="round" d="M12 4.5v15m7.5-7.5h-15" />
</svg>
</button>
</form>
<form action="" method="post" class="inline-flex space-x-1" v-show="labels[{{ $i }}]">
<input type="hidden" name="action" class="block" value="add_label">
<input type="hidden" name="value" value="{{ $label.Key }}">
<select name="key" class="block text-sm select-default !w-auto">
{{ range $k, $project := $.Projects }}
<option value="{{ $project }}">{{ $project }}</option>
{{ end }}
</select>
<button type="submit" class="btn-primary btn-small">
Add project
</button>
</form>
</div>
</div>
</div>
{{end}}