Skip to content

Commit

Permalink
Removes magic JavaScript routing
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnathonKoster committed Mar 19, 2021
1 parent 943f014 commit d76af56
Show file tree
Hide file tree
Showing 40 changed files with 240 additions and 6,175 deletions.
3 changes: 0 additions & 3 deletions resources/dist/js/meerkat.js

This file was deleted.

3,391 changes: 0 additions & 3,391 deletions resources/dist/js/meerkat.js.LICENSE.txt

This file was deleted.

1 change: 0 additions & 1 deletion resources/dist/js/meerkat.js.map

This file was deleted.

2 changes: 1 addition & 1 deletion resources/dist/js/meerkat.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion resources/dist/js/meerkat.min.js.map

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions resources/dist/js/meerkatAvatars.js

This file was deleted.

1,372 changes: 0 additions & 1,372 deletions resources/dist/js/meerkatAvatars.js.LICENSE.txt

This file was deleted.

1 change: 0 additions & 1 deletion resources/dist/js/meerkatAvatars.js.map

This file was deleted.

3 changes: 0 additions & 3 deletions resources/dist/js/meerkatExtend.js

This file was deleted.

715 changes: 0 additions & 715 deletions resources/dist/js/meerkatExtend.js.LICENSE.txt

This file was deleted.

1 change: 0 additions & 1 deletion resources/dist/js/meerkatExtend.js.map

This file was deleted.

2 changes: 1 addition & 1 deletion resources/dist/js/meerkatExtend.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion resources/dist/js/meerkatExtend.min.js.map

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions resources/dist/js/replies-to.js

This file was deleted.

523 changes: 0 additions & 523 deletions resources/dist/js/replies-to.js.LICENSE.txt

This file was deleted.

1 change: 0 additions & 1 deletion resources/dist/js/replies-to.js.map

This file was deleted.

12 changes: 11 additions & 1 deletion resources/ui/src/App/CommentThread/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import Endpoints from '../../Http/endpoints';
import OverviewProvider from '../../Reporting/overviewProvider';
import ControlPanelApplication from '../controlPanelApplication';
import TaskObserver from '../../Tasks/taskObserver';
import Type from '../../Types/type';
import SettingsRepository from '../../Repositories/settingsRepository';

const syncjs = require('syncjs');
Expand Down Expand Up @@ -107,6 +106,16 @@ export default {
ControlPanelApplication.current().controlPanel.message().error(this.trans('actions.check_all_spam_error'));
}.bind(this));
},
onConfigUserAvailable(config) {
this.permissions = Environment.getPermissions();
if (this.permissions.canReportAsHam && this.permissions.canReportAsSpam) {
this.canCheckForSpam = true;
}

this.state.initialPerPage = Environment.UserPreferences.cp_per_page;
this.searchOptions.resultsPerPage = this.state.initialPerPage;
this.updateQueryWithPerPage(this.state.initialPerPage);
},
onCommentsGlobalSpamCheckComplete() {
OverviewProvider.Instance.refresh();

Expand Down Expand Up @@ -291,6 +300,7 @@ export default {
this.applyFromDefaultFilter(poppedValue);
}
}.bind(this);
syncjs.Hubs.config().handledBy(this);

syncjs.Hubs.comments().handledBy(this);

Expand Down
2 changes: 1 addition & 1 deletion resources/ui/src/App/CommentThread/template.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div>
<div class="flex items-center justify-between mb-3">
<div class="flex justify-between">
<h1 class="flex-1">{{ trans('display.header_comments') }}</h1>

<loader v-if="state.loadingData" :display-inline="true" class="mr-1"></loader>
Expand Down
36 changes: 21 additions & 15 deletions resources/ui/src/App/Configurator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,25 @@ export default {
}
},
methods: {
onConfigUserAvailable(config) {
this.reloadConfigState();
},
reloadConfigState() {
if (Environment.isControlPanelConfigEnabled()) {
if (Environment.UserPreferences.isSuper === true) {
this.watchForServerConfigChanges();
this.canChangeConfig = true;
}
}

if (Type.hasValue(Environment.UserPreferences)) {
this.userPreferences.avatarDriver = Environment.UserPreferences.cp_avatar_driver;
this.userPreferences.perPage = Environment.UserPreferences.cp_per_page;
this.userEmail = Environment.UserPreferences.email;
}

this.reloadSettings();
},
watchForServerConfigChanges() {
window.setInterval(function () {
SettingsRepository.Instance.getCurrentChangeSet().then(function (response) {
Expand Down Expand Up @@ -193,22 +212,9 @@ export default {
}
},
created() {
if (Environment.isControlPanelConfigEnabled()) {
if (Environment.UserPreferences.isSuper === true) {
this.watchForServerConfigChanges();
this.canChangeConfig = true;
}
}

syncjs.Hubs.config().handledBy(this);
this.refreshAvatarDrivers();

if (Type.hasValue(Environment.UserPreferences)) {
this.userPreferences.avatarDriver = Environment.UserPreferences.cp_avatar_driver;
this.userPreferences.perPage = Environment.UserPreferences.cp_per_page;
this.userEmail = Environment.UserPreferences.email;
}

this.reloadSettings();
this.reloadConfigState();
}

};
15 changes: 15 additions & 0 deletions resources/ui/src/App/bootstrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import AvatarDriverRegistry from '../Extend/Avatars/avatarDriverRegistry';
import {registerVueFilters} from './registerVueFilters';
import {registerVueComponents} from './registerVueComponents';
import UserSettings from './userSettings';
import SettingsRepository from '../Repositories/settingsRepository';

const syncjs = require('syncjs');

/**
* Provides utilities for bootstrapping Meerkat applications and components.
Expand Down Expand Up @@ -57,6 +60,18 @@ class Bootstrapper {
static bootstrapApplications() {
Environment.Preferences = new UserSettings();

SettingsRepository.Instance.getCurrentUserSettings().then(function (response) {
if (response.success) {
Environment.UserPreferences = response.settings['user'];
Environment.UserContext = response.settings['permissions'];
Environment.Settings.avatarDriver = response.settings['general'].avatarDriver;
Environment.Settings.controlPanelConfigurationEnabled =
response.settings['general'].controlPanelConfigurationEnabled;
Environment.Settings.telemetryEnabled = response.settings['general'].telemetryEnabled;
syncjs.Hubs.config().userAvailable([Environment.UserPreferences]);
}
});

Bootstrapper.registerDependencies();
Bootstrapper.liftExtensibilityDrivers();
Bootstrapper.registerVueJsDependencies();
Expand Down
10 changes: 5 additions & 5 deletions resources/ui/src/Config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ class Environment {
*
* @returns {boolean}
*/
static isControlPanelConfigEnabled(): Boolean {
let curValue = Type.withDefault(Environment.Settings['controlPanelConfigurationEnabled'], '1');
static isControlPanelConfigEnabled(): Boolean {
let curValue = Type.withDefault(Environment.Settings['controlPanelConfigurationEnabled'], true);

return (curValue === '1');
return (curValue === true);
}

/**
Expand All @@ -51,9 +51,9 @@ class Environment {
* @returns {Boolean}
*/
static isTelemetryEnabled(): Boolean {
let curValue = Type.withDefault(Environment.Settings['telemetryEnabled'], '1');
let curValue = Type.withDefault(Environment.Settings['telemetryEnabled'], true);

return (curValue === '1');
return (curValue === true);
}

static getCsrfToken(): string {
Expand Down
26 changes: 26 additions & 0 deletions resources/ui/src/Http/Responses/userConfigurationResponse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import BaseResponse from './baseResponse';
import Type from '../../Types/type';

class UserConfigurationResponse extends BaseResponse {

constructor() {
super();

this.settings = null;
}

static fromApiResponse(apiResponse, err): UserConfigurationResponse {
let response = new UserConfigurationResponse();

BaseResponse.applyResponseToObject(apiResponse, err, response);
response.settings = Type.withDefault(apiResponse[UserConfigurationResponse.ApiSettings], null);

return response;
}

}

UserConfigurationResponse.ApiSettings = 'settings';

export default UserConfigurationResponse;

1 change: 1 addition & 0 deletions resources/ui/src/Http/endpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Endpoints.CommentsCheckForSpam = 'comments/check-for-spam';

Endpoints.TaskGetStatus = 'tasks/status';

Endpoints.CurrentUser = 'settings/current-user';
Endpoints.SettingsFetch = 'settings/fetch';
Endpoints.SettingsSave = 'settings/save';
Endpoints.SettingsGetCurrentChangeSet = 'settings/current-change-set';
Expand Down
20 changes: 20 additions & 0 deletions resources/ui/src/Repositories/settingsRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import SaveSettingsResponse from '../Http/Responses/saveSettingsResponse';
import ValidateAkismetResponse from '../Http/Responses/validateAkismetResponse';
import ChangeSetResponse from '../Http/Responses/changeSetResponse';
import BaseResponse from '../Http/Responses/baseResponse';
import UserConfigurationResponse from '../Http/Responses/userConfigurationResponse';

/**
* Provides a wrapper around Meerkat's configuration-related HTTP API endpoints.
Expand All @@ -23,6 +24,25 @@ class SettingsRepository {
this.client = new Client();
}

getCurrentUserSettings() :Promise<UserConfigurationResponse | ErrorResponse> {
let request = {},
requestHash = hash(request);

return new Promise(function (resolve, reject) {
let requestState = this.shouldProcessRequest(requestHash, 500);

this.client.get(Endpoints.url(Endpoints.CurrentUser), request, requestState)
.then(function (result) {
this.releasePending(requestHash);
resolve(UserConfigurationResponse.fromApiResponse(result, null));
}.bind(this))
.catch(function (err) {
this.releasePending(requestHash);
reject(ErrorResponse.fromError(err));
}.bind(this));
}.bind(this));
}

updatePerPage(perPage) :Promise<BaseResponse | ErrorResponse> {
let request = {'per_page': perPage},
requestHash = hash(request);
Expand Down
59 changes: 0 additions & 59 deletions routes/api.php

This file was deleted.

30 changes: 0 additions & 30 deletions routes/emit.php

This file was deleted.

58 changes: 56 additions & 2 deletions routes/web.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,62 @@
<?php

use Stillat\Meerkat\Addon;
use Illuminate\Support\Facades\Route;

Route::post('/!/Meerkat/socialize', '\Stillat\Meerkat\Http\Controllers\SocializeController@postSocialize');

include_once 'api.php';
include_once 'emit.php';
Route::middleware('statamic.cp.authenticated')->group(function () {
Route::group(['prefix' => Addon::getApiPrefix()], function () {

Route::post('/', '\Stillat\Meerkat\Http\Controllers\Api\IndexController@index');

Route::group(['prefix' => 'telemetry'], function () {
Route::get('/', '\Stillat\Meerkat\Http\Controllers\Api\TelemetryController@index');
Route::get('report', '\Stillat\Meerkat\Http\Controllers\Api\TelemetryController@getReport');
Route::post('submit', '\Stillat\Meerkat\Http\Controllers\Api\TelemetryController@submitReport');
});

Route::group(['prefix' => 'settings'], function () {
Route::get('/current-user', '\Stillat\Meerkat\Http\Controllers\ConfigureController@getCurrentUserSettings');
Route::get('/fetch','\Stillat\Meerkat\Http\Controllers\ConfigureController@getConfiguration');
Route::post('/save','\Stillat\Meerkat\Http\Controllers\ConfigureController@save');
Route::get('/current-change-set','\Stillat\Meerkat\Http\Controllers\ConfigureController@getCurrentConfigHash');
Route::post('/validate-akismet', '\Stillat\Meerkat\Http\Controllers\ConfigureController@validateAkismetApiKey');
Route::post('/update-per-page', '\Stillat\Meerkat\Http\Controllers\ConfigureController@updateUserPerPage');

});

Route::group(['prefix' => 'comments'], function () {
Route::post('/search', '\Stillat\Meerkat\Http\Controllers\Api\CommentsController@search');
Route::post('/update', '\Stillat\Meerkat\Http\Controllers\Api\UpdateCommentController@updateComment');
Route::post('/reply', '\Stillat\Meerkat\Http\Controllers\Api\ReplyCommentController@reply');
Route::post('/publish', '\Stillat\Meerkat\Http\Controllers\Api\PublishCommentController@publishComment');
Route::post('/publish-many', '\Stillat\Meerkat\Http\Controllers\Api\PublishCommentController@publishMany');
Route::post('/unpublish', '\Stillat\Meerkat\Http\Controllers\Api\UnpublishCommentController@unPublishComment');
Route::post('/unpublish-many', '\Stillat\Meerkat\Http\Controllers\Api\UnpublishCommentController@unPublishMany');
Route::post('/remove', '\Stillat\Meerkat\Http\Controllers\Api\RemoveCommentController@deleteComment');
Route::post('/remove-many', '\Stillat\Meerkat\Http\Controllers\Api\RemoveCommentController@deleteMany');
Route::post('/report-spam', '\Stillat\Meerkat\Http\Controllers\Api\SpamController@markAsSpam');
Route::post('/report-many-spam', '\Stillat\Meerkat\Http\Controllers\Api\SpamController@markManyAsSpam');
Route::post('/remove-all-spam', '\Stillat\Meerkat\Http\Controllers\Api\SpamController@removeAllSpam');
Route::post('/report-ham', '\Stillat\Meerkat\Http\Controllers\Api\NotSpamController@markAsNotSpam');
Route::post('/report-many-ham', '\Stillat\Meerkat\Http\Controllers\Api\NotSpamController@markManyAsNotSpam');

Route::post('/check-for-spam', '\Stillat\Meerkat\Http\Controllers\Api\CheckForSpamController@checkForSpam');
});

Route::group(['prefix' => 'tasks'], function () {
Route::get('status', '\Stillat\Meerkat\Http\Controllers\Api\TaskController@getTaskStatus');
});

Route::group(['prefix' => 'export'], function () {
Route::get('csv', '\Stillat\Meerkat\Http\Controllers\Api\ExportController@csv');
Route::get('json', '\Stillat\Meerkat\Http\Controllers\Api\ExportController@json');
});

Route::group(['prefix' => 'reporting'], function () {
Route::get('overview', '\Stillat\Meerkat\Http\Controllers\Api\ReportingController@getReportOverview');
});

});
});
2 changes: 1 addition & 1 deletion src/Addon.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Addon
public const CODE_ADDON_NAME = 'meerkat';
public const ROUTE_PREFIX = 'meerkat';
public const ADDON_ID = 'stillat/meerkat';
public const VERSION = '2.4.0-beta3';
public const VERSION = '2.4.2-beta3';

/**
* Gets the addon API prefix.
Expand Down
2 changes: 1 addition & 1 deletion src/Comments/CommentMutationPipeline.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class CommentMutationPipeline extends EventPipeline implements CommentMutationPi

/**
* Attempts to fire Statamic's EntrySaved event for the provided thread context.
*
*
* @param string $threadId The entry identifier.
*/
private function fireStatamicEntrySavedEvent($threadId)
Expand Down
Loading

0 comments on commit d76af56

Please sign in to comment.