forked from statamic/cms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Jesse Leite <[email protected]> Co-authored-by: Jack McDade <[email protected]> Co-authored-by: StyleCI Bot <[email protected]>
- Loading branch information
1 parent
63e3755
commit 62c6fed
Showing
20 changed files
with
876 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
<template> | ||
|
||
<publish-container | ||
ref="container" | ||
:name="name" | ||
:blueprint="blueprint" | ||
v-model="currentValues" | ||
reference="collection" | ||
:meta="meta" | ||
:errors="errors" | ||
v-slot="{ setFieldValue, setFieldMeta }" | ||
> | ||
<div> | ||
<breadcrumbs v-if="breadcrumbs" :crumbs="breadcrumbs" /> | ||
|
||
<div class="flex items-center mb-3"> | ||
<h1 class="flex-1">{{ title }}</h1> | ||
|
||
<div class="ml-2 text-left" :class="{ 'btn-group': hasSaveAsOptions }"> | ||
<button | ||
class="btn-primary pl-2" | ||
:class="{ 'disabled': !isDirty }" | ||
:disabled="!isDirty" | ||
@click="save" | ||
v-text="__('Save')" /> | ||
|
||
<dropdown-list v-if="hasSaveAsOptions" class="ml-0"> | ||
<template #trigger> | ||
<button class="btn-primary rounded-l-none flex items-center"> | ||
<svg-icon name="chevron-down-xs" class="w-2" /> | ||
</button> | ||
</template> | ||
<h6 class="p-1">{{ __('Save to') }}...</h6> | ||
<dropdown-item v-for="option in saveAsOptions" :key="option.url" @click="saveAs(option.url)"> | ||
<div class="flex items-start pr-2"> | ||
<svg-icon :name="option.icon" class="text-grey flex-shrink-0 mr-1 w-4 group-hover:text-white" /> | ||
<span class="whitespace-normal">{{ option.label }}</span> | ||
</div> | ||
</dropdown-item> | ||
</dropdown-list> | ||
</div> | ||
</div> | ||
|
||
<publish-sections | ||
@updated="setFieldValue" | ||
@meta-updated="setFieldMeta" | ||
:can-toggle-labels="canToggleLabels" | ||
:enable-sidebar="hasSidebar" | ||
:read-only="readOnly" /> | ||
</div> | ||
</publish-container> | ||
|
||
</template> | ||
|
||
<script> | ||
export default { | ||
props: { | ||
blueprint: { required: true, type: Object }, | ||
meta: { required: true, type: Object }, | ||
values: { required: true, type: Object }, | ||
title: { required: true, type: String }, | ||
name: { type: String, default: 'base' }, | ||
breadcrumbs: Array, | ||
action: String, | ||
canToggleLabels: { type: Boolean, default: true }, | ||
readOnly: { type: Boolean, default: false }, | ||
reloadOnSave: { type: Boolean, default: false }, | ||
saveAsOptions: { type: Array, default: () => [] }, | ||
}, | ||
data() { | ||
return { | ||
saving: false, | ||
currentValues: this.values, | ||
error: null, | ||
errors: {}, | ||
hasSidebar: this.blueprint.sections.map(section => section.handle).includes('sidebar'), | ||
} | ||
}, | ||
computed: { | ||
hasSaveAsOptions() { | ||
return this.saveAsOptions.length; | ||
}, | ||
isDirty() { | ||
return this.$dirty.has(this.name); | ||
} | ||
}, | ||
methods: { | ||
clearErrors() { | ||
this.error = null; | ||
this.errors = {}; | ||
}, | ||
save() { | ||
this.saveAs(this.action); | ||
}, | ||
saveAs(url) { | ||
this.saving = true; | ||
this.clearErrors(); | ||
this.$axios | ||
.patch(url, this.currentValues) | ||
.then(() => { | ||
this.$refs.container.saved(); | ||
location.reload(); | ||
}) | ||
.catch(e => this.handleAxiosError(e)); | ||
}, | ||
handleAxiosError(e) { | ||
this.saving = false; | ||
if (e.response && e.response.status === 422) { | ||
const { message, errors } = e.response.data; | ||
this.error = message; | ||
this.errors = errors; | ||
this.$toast.error(message); | ||
} else { | ||
const message = data_get(e, 'response.data.message'); | ||
this.$toast.error(message || e); | ||
console.log(e); | ||
} | ||
}, | ||
}, | ||
created() { | ||
this.$keys.bindGlobal(['mod+s'], e => { | ||
e.preventDefault(); | ||
this.save(); | ||
}); | ||
}, | ||
watch: { | ||
saving(saving) { | ||
this.$progress.loading('preferences-edit-form', saving); | ||
} | ||
}, | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
@extends('statamic::layout') | ||
@section('title', $title) | ||
|
||
@section('content') | ||
|
||
@if($showBreadcrumb) | ||
@include('statamic::partials.breadcrumb', [ | ||
'url' => cp_route('preferences.index'), | ||
'title' => __('Preferences'), | ||
]) | ||
@endif | ||
|
||
<preferences-edit-form | ||
title="{{ $title }}" | ||
:blueprint='@json($blueprint)' | ||
:meta='@json($meta)' | ||
:values='@json($values)' | ||
action="{{ $actionUrl }}" | ||
:save-as-options="{{ json_encode($saveAsOptions) }}" | ||
></preferences-edit-form> | ||
|
||
@stop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
@extends('statamic::layout') | ||
@section('title', __('Preferences')) | ||
|
||
@section('content') | ||
|
||
<div class="flex justify-between items-center mb-3"> | ||
<h1>@yield('title')</h1> | ||
</div> | ||
|
||
<div class="card p-0 mb-2"> | ||
<table class="data-table"> | ||
<tr> | ||
<td> | ||
<div class="flex items-center"> | ||
<div class="w-4 h-4 mr-2">@cp_svg('earth')</div> | ||
<a href="{{ cp_route('preferences.default.edit') }}">{{ __('Default') }}</a> | ||
</div> | ||
</td> | ||
<td class="text-right text-2xs text-grey-50"> | ||
@if (!empty(Statamic\Facades\Preference::default()->all())) | ||
{{ __('Modified') }} | ||
@endif | ||
</td> | ||
</tr> | ||
</table> | ||
</div> | ||
|
||
@if (Statamic\Facades\Role::all()->isNotEmpty()) | ||
<h3 class="little-heading pl-0 mb-1">{{ __('Override For Role') }}</h3> | ||
<div class="card p-0 mb-2"> | ||
<table class="data-table"> | ||
@foreach (Statamic\Facades\Role::all() as $role) | ||
<tr> | ||
<td> | ||
<div class="flex items-center"> | ||
<div class="w-4 h-4 mr-2">@cp_svg('shield-key')</div> | ||
<a href="{{ cp_route('preferences.role.edit', [$role->handle()]) }}">{{ __($role->title()) }}</a> | ||
</div> | ||
</td> | ||
<td class="text-right text-2xs text-grey-50"> | ||
@if (!empty($role->preferences())) | ||
{{ __('Modified') }} | ||
@endif | ||
</td> | ||
</tr> | ||
@endforeach | ||
</table> | ||
</div> | ||
@endif | ||
|
||
<h3 class="little-heading pl-0 mb-1">{{ __('Override For User') }}</h3> | ||
<div class="card p-0 mb-2"> | ||
<table class="data-table"> | ||
<tr> | ||
<td> | ||
<div class="flex items-center"> | ||
<div class="w-4 h-4 mr-2">@cp_svg('user')</div> | ||
<a href="{{ cp_route('preferences.user.edit') }}">{{ __('My Preferences') }}</a> | ||
</div> | ||
</td> | ||
<td class="text-right text-2xs text-grey-50"> | ||
@if (!empty(auth()->user()->preferences())) | ||
{{ __('Modified') }} | ||
@endif | ||
</td> | ||
</tr> | ||
</table> | ||
</div> | ||
|
||
@include('statamic::partials.docs-callout', [ | ||
'topic' => __('Preferences'), | ||
'url' => Statamic::docsUrl('preferences') | ||
]) | ||
@endsection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/Http/Controllers/CP/Preferences/DefaultPreferenceController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Statamic\Http\Controllers\CP\Preferences; | ||
|
||
use Illuminate\Http\Request; | ||
use Statamic\Facades\Preference; | ||
use Statamic\Http\Controllers\CP\CpController; | ||
|
||
class DefaultPreferenceController extends CpController | ||
{ | ||
use ManagesPreferences; | ||
|
||
public function edit() | ||
{ | ||
return $this->view( | ||
__('Default'), | ||
cp_route('preferences.default.update'), | ||
Preference::default()->all() | ||
); | ||
} | ||
|
||
public function update(Request $request) | ||
{ | ||
return $this->updatePreferences($request, Preference::default()); | ||
} | ||
|
||
private function ignoreSaveAsOption() | ||
{ | ||
return 'default'; | ||
} | ||
} |
Oops, something went wrong.