Skip to content

Commit

Permalink
Merge branch 'feat/setup-wizard' into feat/last-bits
Browse files Browse the repository at this point in the history
  • Loading branch information
squigglybob committed Dec 18, 2024
2 parents 16384c1 + 2165853 commit 3b8ef53
Show file tree
Hide file tree
Showing 8 changed files with 273 additions and 4 deletions.
22 changes: 21 additions & 1 deletion dt-core/admin/admin-settings-endpoints.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,34 @@ public function add_api_routes() {
'permission_callback' => [ $this, 'default_permission_check' ],
]
);

register_rest_route(
$this->namespace, '/modules-update', [
'methods' => 'POST',
'callback' => [ $this, 'update_modules' ],
'permission_callback' => [ $this, 'default_permission_check' ],
]
);
register_rest_route(
$this->namespace, '/update-dt-options', [
'methods' => 'POST',
'callback' => [ $this, 'update_dt_options' ],
'permission_callback' => [ $this, 'default_permission_check' ],
]
);
}

public function update_dt_options( WP_REST_REQUEST $request ){
$params = $request->get_params();
$updated = false;
foreach ( $params as $option_key => $option_value ){
//only allow updating D.T options
if ( strpos( $option_key, 'dt_' ) !== 0 ){
continue;
}
update_option( $option_key, $option_value );
$updated = true;
}
return $updated;
}

public function update_modules( WP_REST_REQUEST $request ) {
Expand Down
1 change: 1 addition & 0 deletions dt-core/admin/components/setup-wizard-celebration.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export class SetupWizardCelebration extends OpenLitElement {
nextLabel=${this.translations.finish}
@next=${this.next}
@back=${this.back}
nextLabel="Close Wizard"
></setup-wizard-controls>
</div>
`;
Expand Down
2 changes: 2 additions & 0 deletions dt-core/admin/components/setup-wizard-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export class SetupWizardControls extends OpenLitElement {
backLabel: { type: String },
nextLabel: { type: String },
skipLabel: { type: String },
saving: { type: Boolean },
};
}
back() {
Expand Down Expand Up @@ -37,6 +38,7 @@ export class SetupWizardControls extends OpenLitElement {
`}
<button @click=${this.next} class="btn-primary">
${this.nextLabel ?? 'Next'}
${this.saving ? html`<span class="spinner light"></span>` : ''}
</button>
</div>
`;
Expand Down
210 changes: 210 additions & 0 deletions dt-core/admin/components/setup-wizard-keys.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
import {
html,
css,
} from 'https://cdn.jsdelivr.net/gh/lit/[email protected]/all/lit-all.min.js';
import { OpenLitElement } from './setup-wizard-open-element.js';

export class SetupWizardKeys extends OpenLitElement {
static styles = [
css`
:host {
display: block;
}
`,
];

static get properties() {
return {
step: { type: Object },
firstStep: { type: Boolean },
_options: { type: Object },
_saving: { type: Boolean, attribute: false },
};
}

back() {
this.dispatchEvent(new CustomEvent('back'));
}
async next() {
this._saving = true;
await window.dt_admin_shared.update_dt_options(this._options);
this._saving = false;

this.dispatchEvent(new CustomEvent('next'));
}

constructor() {
super();
this._saving = false;
this._options = {
dt_mapbox_api_key: '',
dt_google_map_key: '',
};
this.show_mapbox_instructions = false;
this.show_google_instructions = false;
}

render() {
this._options.dt_mapbox_api_key = this.step.config.dt_mapbox_api_key;
this._options.dt_google_map_key = this.step.config.dt_google_map_key;
return html`
<div class="cover">
<div class="content flow">
<h2>Mapping and Geocoding</h2>
<table style="width: 100%">
<thead>
<tr>
<th>Key</th>
<th>Description</th>
<th style="width: 30%">Value</th>
</tr>
</thead>
<tbody>
<tr>
<td>Mapbox key</td>
<td>
Upgrade maps and get precise locations with a MapBox key.
<br />
<button
type="button"
@click=${() => {
this.show_mapbox_instructions =
!this.show_mapbox_instructions;
this.requestUpdate();
}}
>
Show Instructions
</button>
<div
?hidden=${!this.show_mapbox_instructions}
style="max-width: 600px;font-size: 14px"
>
<ol>
<li>
Go to
<a href="https://www.mapbox.com/" target="_blank"
>MapBox.com</a
>.
</li>
<li>
Register for a new account (<a
href="https://account.mapbox.com/auth/signup/"
target="_blank"
>MapBox.com</a
>)<br />
<em
>(email required. A credit card might be required,
though you will likely not go over the free monthly
quota.)</em
>
</li>
<li>
Once registered, go to your account home page. (<a
target="_blank"
href="https://account.mapbox.com/"
>Account Page</a
>)<br />
</li>
<li>
Inside the section labeled "Access Tokens", either
create a new token or use the default token provided.
Copy this token.
</li>
<li>
Paste the token into the "Mapbox API Token" field in the
box above.
</li>
</ol>
</div>
</td>
<td>
<input
style="width: 100%"
type="text"
name="mapbox"
.value=${this.step.config.dt_mapbox_api_key || ''}
@input=${(e) => {
this._options.dt_mapbox_api_key = e.target.value;
}}
/>
</td>
</tr>
<tr>
<td>Google key</td>
<td>
Upgrade maps and get even more precise locations with a Google
key.
<br />
<button
type="button"
@click=${() => {
this.show_google_instructions =
!this.show_google_instructions;
this.requestUpdate();
}}
>
Show Instructions
</button>
<div
?hidden=${!this.show_google_instructions}
style="max-width: 600px;font-size: 14px"
>
<ol>
<li>
Go to
<a href="https://console.cloud.google.com"
>https://console.cloud.google.com</a
>.
</li>
<li>
Register with your Google Account or Gmail Account
</li>
<li>Once registered, create a new project.<br /></li>
<li>
Then go to APIs & Services > Credentials and "Create
Credentials" API Key. Copy this key.
</li>
<li>
Paste the key into the "Google API Key" field in the box
above here in the Disciple.Tools Mapping Admin.
</li>
<li>
Again, in Google Cloud Console, in APIs & Services go to
Library. Find and enable: (1) Maps Javascript API, (2)
Places API, and (3) GeoCoding API.
</li>
<li>
Lastly, in in Credentials for the API key it is
recommended in the settings of the API key to be set
"None" for Application Restrictions and "Don't restrict
key" in API Restrictions.
</li>
</ol>
</div>
</td>
<td>
<input
style="width: 100%"
type="text"
name="mapbox"
.value=${this.step.config.dt_google_map_key || ''}
@input=${(e) => {
this._options.dt_google_map_key = e.target.value;
}}
/>
</td>
</tr>
</tbody>
</table>
</div>
<setup-wizard-controls
?hideBack=${this.firstStep}
@next=${this.next}
@back=${this.back}
.saving=${this._saving}
></setup-wizard-controls>
</div>
`;
}
}
customElements.define('setup-wizard-keys', SetupWizardKeys);
5 changes: 3 additions & 2 deletions dt-core/admin/components/setup-wizard-plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ export class SetupWizardPlugins extends OpenLitElement {
render() {
return html`
<div class="cover">
<div class="content">
<div class="content flow">
<h2>Recommended Plugins</h2>
<table>
<thead>
<tr>
Expand Down Expand Up @@ -123,7 +124,7 @@ export class SetupWizardPlugins extends OpenLitElement {
</div>
<setup-wizard-controls
?hideBack=${this.firstStep}
nextLabel="install and activate selected plugins"
nextLabel="Install and Activate Selected Plugins"
@next=${this.next}
@back=${this.back}
@skip=${this.skip}
Expand Down
19 changes: 18 additions & 1 deletion dt-core/admin/components/setup-wizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ export class SetupWizard extends LitElement {
border-radius: 8px;
cursor: pointer;
background-color: var(--default-color);
<<<<<<< HEAD
transition: all 120ms linear;
=======
transition: background-color 120ms linear;
box-shadow: 1px 1px 3px 0 var(--default-dark);
>>>>>>> feat/setup-wizard
}
button:hover,
button:active,
Expand Down Expand Up @@ -297,13 +302,21 @@ export class SetupWizard extends LitElement {
opacity: 0.7;
width: 20px;
height: 20px;
display: block;
display: inline-block;
}
.spinner.light {
background: url('images/wpspin_light-2x.gif') no-repeat;
background-size: 20px 20px;
}
button .spinner {
vertical-align: bottom;
}
table {
margin-bottom: 1rem;
}
table td {
padding: 0.5rem;
vertical-align: top;
}
table thead tr {
background-color: var(--default-color);
Expand Down Expand Up @@ -333,6 +346,10 @@ export class SetupWizard extends LitElement {
const url = new URL(location.href);

this.isKitchenSink = url.searchParams.has('kitchen-sink');
//get step number from step url param
if (url.searchParams.has('step')) {
this.currentStepNumber = parseInt(url.searchParams.get('step'));
}
}

firstUpdated() {
Expand Down
8 changes: 8 additions & 0 deletions dt-core/admin/js/dt-shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ window.dt_admin_shared = {
.replace(/"/g, '&quot;')
.replace(/'/g, '&apos;');
},

/**
* Update options. Provide an object with the options to update.
* @param options
*/
update_dt_options: (options) =>
makeRequest('POST', 'update-dt-options', options, 'dt-admin-settings/'),

plugin_install: (download_url) =>
makeRequest(
'POST',
Expand Down
10 changes: 10 additions & 0 deletions dt-core/admin/menu/menu-setup-wizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public function enqueue_scripts(){
dt_theme_enqueue_script( 'setup-wizard-modules', 'dt-core/admin/components/setup-wizard-modules.js', [ 'setup-wizard', 'setup-wizard-open-element' ], true );
dt_theme_enqueue_script( 'setup-wizard-plugins', 'dt-core/admin/components/setup-wizard-plugins.js', [ 'setup-wizard', 'setup-wizard-open-element' ], true );
dt_theme_enqueue_script( 'setup-wizard-details', 'dt-core/admin/components/setup-wizard-details.js', [ 'setup-wizard', 'setup-wizard-open-element' ], true );
dt_theme_enqueue_script( 'setup-wizard-keys', 'dt-core/admin/components/setup-wizard-keys.js', [ 'setup-wizard', 'setup-wizard-open-element' ], true );
dt_theme_enqueue_script( 'setup-wizard-controls', 'dt-core/admin/components/setup-wizard-controls.js', [ 'setup-wizard', 'setup-wizard-open-element' ], true );
dt_theme_enqueue_script( 'setup-wizard-intro', 'dt-core/admin/components/setup-wizard-intro.js', [ 'setup-wizard', 'setup-wizard-open-element' ], true );
dt_theme_enqueue_script( 'setup-wizard-celebration', 'dt-core/admin/components/setup-wizard-celebration.js', [ 'setup-wizard', 'setup-wizard-open-element' ], true );
Expand Down Expand Up @@ -161,6 +162,15 @@ public function setup_wizard_steps() {
'description' => 'Choose which plugins to install.',
'component' => 'setup-wizard-plugins',
],
[
'name' => 'Site keys',
'description' => 'Fill in some site details',
'component' => 'setup-wizard-keys',
'config' => [
'dt_google_map_key' => Disciple_Tools_Google_Geocode_API::get_key(),
'dt_mapbox_api_key' => DT_Mapbox_API::get_key(),
],
],
[
'key' => 'celebration',
'component' => 'setup-wizard-celebration',
Expand Down

0 comments on commit 3b8ef53

Please sign in to comment.