Inherit all stimulus controllers from base_controller

This commit is contained in:
Eugene Burmakin 2025-02-15 16:48:03 +01:00
parent 7dfec304e4
commit aaa3c77162
16 changed files with 71 additions and 30 deletions

View file

@ -10,6 +10,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Fixed a bug where background jobs to import Immich and Photoprism geolocation data data could not be created by non-admin users.
### Changed
- Restrict access to Sidekiq in non self-hosted mode.
- Restrict access to background jobs in non self-hosted mode.
- Restrict access to users management in non self-hosted mode.
# 0.24.1 - 2025-02-13
## Custom map tiles

View file

@ -3,7 +3,7 @@
class ApplicationController < ActionController::Base
include Pundit::Authorization
before_action :unread_notifications
before_action :unread_notifications, :set_self_hosted_status
protected
@ -24,4 +24,10 @@ class ApplicationController < ActionController::Base
redirect_to root_path, notice: 'You are not authorized to perform this action.', status: :see_other
end
private
def set_self_hosted_status
@self_hosted = DawarichSettings.self_hosted?
end
end

View file

@ -0,0 +1,23 @@
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
static values = {
selfHosted: Boolean
}
// Every controller that extends BaseController and uses initialize()
// should call super.initialize()
// Example:
// export default class extends BaseController {
// initialize() {
// super.initialize()
// }
// }
initialize() {
// Get the self-hosted value from the HTML root element
if (!this.hasSelfHostedValue) {
const selfHosted = document.documentElement.dataset.selfHosted === 'true'
this.selfHostedValue = selfHosted
}
}
}

View file

@ -1,7 +1,7 @@
import { Controller } from "@hotwired/stimulus"
import BaseController from "./base_controller"
// Connects to data-controller="checkbox-select-all"
export default class extends Controller {
export default class extends BaseController {
static targets = ["parent", "child"]
connect() {

View file

@ -2,9 +2,9 @@
// - trips/new
// - trips/edit
import { Controller } from "@hotwired/stimulus"
import BaseController from "./base_controller"
export default class extends Controller {
export default class extends BaseController {
static targets = ["startedAt", "endedAt", "apiKey"]
static values = { tripsId: String }

View file

@ -1,7 +1,7 @@
import { Controller } from "@hotwired/stimulus";
import BaseController from "./base_controller";
import consumer from "../channels/consumer";
export default class extends Controller {
export default class extends BaseController {
static targets = ["index"];
connect() {

View file

@ -1,8 +1,8 @@
import { Controller } from "@hotwired/stimulus"
import BaseController from "./base_controller"
import L from "leaflet"
import { showFlashMessage } from "../maps/helpers"
export default class extends Controller {
export default class extends BaseController {
static targets = ["urlInput", "mapContainer", "saveButton"]
DEFAULT_TILE_URL = 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'

View file

@ -13,7 +13,7 @@ import {
import { fetchAndDrawAreas, handleAreaCreated } from "../maps/areas";
import { showFlashMessage, fetchAndDisplayPhotos, debounce } from "../maps/helpers";
import { showFlashMessage, fetchAndDisplayPhotos } from "../maps/helpers";
import {
osmMapLayer,
@ -31,8 +31,9 @@ import { countryCodesMap } from "../maps/country_codes";
import "leaflet-draw";
import { initializeFogCanvas, drawFogCanvas, createFogOverlay } from "../maps/fog_of_war";
import { TileMonitor } from "../maps/tile_monitor";
import BaseController from "./base_controller";
export default class extends Controller {
export default class extends BaseController {
static targets = ["container"];
settingsButtonAdded = false;
@ -41,6 +42,7 @@ export default class extends Controller {
trackedMonthsCache = null;
connect() {
super.connect();
console.log("Map controller connected");
this.apiKey = this.element.dataset.api_key;

View file

@ -1,11 +1,12 @@
import { Controller } from "@hotwired/stimulus"
import BaseController from "./base_controller"
import consumer from "../channels/consumer"
export default class extends Controller {
export default class extends BaseController {
static targets = ["badge", "list"]
static values = { userId: Number }
initialize() {
super.initialize()
this.subscription = null
}

View file

@ -1,6 +1,6 @@
import { Controller } from "@hotwired/stimulus"
import BaseController from "./base_controller"
export default class extends Controller {
export default class extends BaseController {
static values = {
timeout: Number
}

View file

@ -1,10 +1,10 @@
// This controller is being used on:
// - trips/index
import { Controller } from "@hotwired/stimulus"
import BaseController from "./base_controller"
import L from "leaflet"
export default class extends Controller {
export default class extends BaseController {
static values = {
tripId: Number,
path: String,

View file

@ -3,7 +3,7 @@
// - trips/edit
// - trips/new
import { Controller } from "@hotwired/stimulus"
import BaseController from "./base_controller"
import L from "leaflet"
import {
osmMapLayer,
@ -22,7 +22,7 @@ import {
showFlashMessage
} from '../maps/helpers';
export default class extends Controller {
export default class extends BaseController {
static targets = ["container", "startedAt", "endedAt"]
static values = { }

View file

@ -1,12 +1,12 @@
import { Controller } from "@hotwired/stimulus"
import L, { latLng } from "leaflet";
import { osmMapLayer } from "../maps/layers";
import BaseController from "./base_controller"
import L from "leaflet"
import { osmMapLayer } from "../maps/layers"
// This controller is used to display a map of all coordinates for a visit
// on the "Map" modal of a visit on the Visits page
export default class extends Controller {
static targets = ["container"];
export default class extends BaseController {
static targets = ["container"]
connect() {
this.coordinates = JSON.parse(this.element.dataset.coordinates);

View file

@ -1,10 +1,13 @@
import { Controller } from "@hotwired/stimulus";
import BaseController from "./base_controller"
export default class extends Controller {
export default class extends BaseController {
static targets = ["name", "input"]
connect() {
this.visitId = this.element.dataset.id;
this.apiKey = this.element.dataset.api_key;
this.visitId = this.element.dataset.id;
this.element.addEventListener("visit-name:updated", this.updateAll.bind(this));
}
// Action to handle selection change

View file

@ -1,7 +1,7 @@
import { Controller } from "@hotwired/stimulus";
import BaseController from "./base_controller"
// This controller is used to handle the updating of visit names on the Visits page
export default class extends Controller {
export default class extends BaseController {
static targets = ["name", "input"];
connect() {

View file

@ -1,5 +1,5 @@
<!DOCTYPE html>
<html data-theme="<%= app_theme %>">
<html data-theme="<%= app_theme %>" data-self-hosted="<%= @self_hosted %>">
<head>
<title><%= full_title(yield(:title)) %></title>
<meta name="viewport" content="width=device-width,initial-scale=1">