Skip to content

Commit

Permalink
Add service management page Fixes GladysAssistant#910
Browse files Browse the repository at this point in the history
  • Loading branch information
atrovato committed Nov 6, 2020
1 parent 6fb3e75 commit 92a541c
Show file tree
Hide file tree
Showing 24 changed files with 963 additions and 105 deletions.
37 changes: 37 additions & 0 deletions front/src/actions/integration.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import get from 'get-value';
import update from 'immutability-helper';

import { integrations, integrationsByType, categories } from '../config/integrations';

const actions = store => ({
Expand All @@ -11,6 +13,41 @@ const actions = store => ({
searchKeyword: ''
});
},
async getServices(state, podId = null) {
try {
const query = {
pod_id: podId
};
const services = await state.httpClient.get(`/api/v1/service`, query);
services.sort((s1, s2) => s1.name.localeCompare(s2.name));
store.setState({
services
});
} catch (e) {
console.log(e);
}
},
async actionOnService(state, serviceName, action, podId = null) {
const query = {
pod_id: podId
};
const service = await state.httpClient.post(`/api/v1/service/${serviceName}/${action}`, query);

const serviceIndex = state.services.findIndex(s => s.selector === service.selector);
const services = update(state.services, {
$splice: [[serviceIndex, 1, service]]
});

store.setState({
services
});
},
async startService(state, serviceName, podId = null) {
await this.actionOnService(state, serviceName, 'start', podId);
},
async stopService(state, serviceName, podId = null) {
await this.actionOnService(state, serviceName, 'stop', podId);
},
async getIntegrationByName(state, name, podId = null) {
try {
const query = {
Expand Down
2 changes: 2 additions & 0 deletions front/src/components/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import ProfilePage from '../routes/profile';
import SettingsSessionPage from '../routes/settings/settings-session';
import SettingsHousePage from '../routes/settings/settings-house';
import SettingsSystemPage from '../routes/settings/settings-system';
import SettingsServicePage from '../routes/settings/settings-service';
import SettingsGateway from '../routes/settings/settings-gateway';
import SettingsBackup from '../routes/settings/settings-backup';
import SettingsBilling from '../routes/settings/settings-billing';
Expand Down Expand Up @@ -201,6 +202,7 @@ const AppRouter = connect(
<SettingsHousePage path="/dashboard/settings/house" />
<SettingsSystemPage path="/dashboard/settings/system" />
<SettingsGateway path="/dashboard/settings/gateway" />
<SettingsServicePage path="/dashboard/settings/service" />
<SettingsBackup path="/dashboard/settings/backup" />
<Error type="404" default />
</Router>
Expand Down
167 changes: 167 additions & 0 deletions front/src/config/demo.json
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,173 @@
"created_at": 1561506899
}
],
"get /api/v1/service": [
{
"id": "27c96cfe-98ce-437b-a83f-5b13e0605203",
"pod_id": null,
"name": "example",
"selector": "example",
"version": "0.1.0",
"has_message_feature": false,
"status": "LOADING",
"created_at": "2020-04-11T18:41:40.051Z",
"updated_at": "2020-10-18T10:13:22.365Z"
},
{
"id": "40262062-2e71-412c-8da0-70bd03f03b90",
"pod_id": null,
"name": "philips-hue",
"selector": "philips-hue",
"version": "0.1.0",
"has_message_feature": false,
"status": "READY",
"created_at": "2020-04-11T18:41:40.052Z",
"updated_at": "2020-10-30T07:44:07.731Z"
},
{
"id": "4cd73c14-a929-4af0-a5e2-baed35802224",
"pod_id": null,
"name": "rtsp-camera",
"selector": "rtsp-camera",
"version": "0.1.0",
"has_message_feature": false,
"status": "READY",
"created_at": "2020-04-11T18:41:40.053Z",
"updated_at": "2020-10-30T07:44:07.694Z"
},
{
"id": "0c27de72-ced7-4f7f-8950-473b9e904e71",
"pod_id": null,
"name": "telegram",
"selector": "telegram",
"version": "0.1.0",
"has_message_feature": true,
"status": "ERROR",
"created_at": "2020-04-11T18:41:40.053Z",
"updated_at": "2020-10-30T07:44:07.518Z"
},
{
"id": "09a3e250-940a-4f52-8595-e6268ffd7198",
"pod_id": null,
"name": "usb",
"selector": "usb",
"version": "0.1.0",
"has_message_feature": false,
"status": "READY",
"created_at": "2020-04-11T18:41:40.053Z",
"updated_at": "2020-10-30T07:44:07.660Z"
},
{
"id": "8070fb7c-908f-426a-bbbf-12dce1f27549",
"pod_id": null,
"name": "darksky",
"selector": "darksky",
"version": "0.1.0",
"has_message_feature": false,
"status": "UNKNOWN",
"created_at": "2020-04-11T18:41:40.054Z",
"updated_at": "2020-04-11T18:41:40.054Z"
},
{
"id": "366fd9d7-bfbf-4c13-bd8c-4cc777799142",
"pod_id": null,
"name": "xiaomi",
"selector": "xiaomi",
"version": "0.1.0",
"has_message_feature": false,
"status": "READY",
"created_at": "2020-04-11T18:41:40.055Z",
"updated_at": "2020-10-30T07:44:07.474Z"
},
{
"id": "3772bbf5-b1d7-441f-9bd4-ef94920e31cd",
"pod_id": null,
"name": "zwave",
"selector": "zwave",
"version": "0.1.0",
"has_message_feature": false,
"status": "ERROR",
"created_at": "2020-04-11T18:41:40.056Z",
"updated_at": "2020-10-30T07:44:07.594Z"
},
{
"id": "7355bc7f-4109-40ba-819f-fb03f91969b0",
"pod_id": null,
"name": "tasmota",
"selector": "tasmota",
"version": "0.1.0",
"has_message_feature": false,
"status": "READY",
"created_at": "2020-04-11T18:41:40.056Z",
"updated_at": "2020-10-30T07:44:07.627Z"
},
{
"id": "2e0bc58b-11e2-4176-8ad3-9ebc8cdd2318",
"pod_id": null,
"name": "mqtt",
"selector": "mqtt",
"version": "0.1.0",
"has_message_feature": false,
"status": "ERROR",
"created_at": "2020-04-11T18:41:40.057Z",
"updated_at": "2020-10-30T07:44:07.785Z"
},
{
"id": "d97ba3fa-872f-4ecc-879f-46c55a2930c6",
"pod_id": null,
"name": "google-actions",
"selector": "google-actions",
"version": "0.1.0",
"has_message_feature": false,
"status": "UNKNOWN",
"created_at": "2020-04-11T18:41:40.111Z",
"updated_at": "2020-04-11T18:41:40.111Z"
},
{
"id": "6d3c7a63-e4b8-4650-bcd3-50cf42b2996f",
"pod_id": null,
"name": "caldav",
"selector": "caldav",
"version": "0.1.0",
"has_message_feature": false,
"status": "READY",
"created_at": "2020-04-16T19:38:21.885Z",
"updated_at": "2020-10-30T07:44:07.558Z"
},
{
"id": "39a278e9-66da-47cb-bdaa-264ba6418091",
"pod_id": null,
"name": "openweather",
"selector": "openweather",
"version": "0.1.0",
"has_message_feature": false,
"status": "ERROR",
"created_at": "2020-08-19T13:04:57.309Z",
"updated_at": "2020-10-30T07:44:07.814Z"
},
{
"id": "9682e167-e07f-4823-bd31-a60f957842e0",
"pod_id": null,
"name": "broadlink",
"selector": "broadlink",
"version": "0.1.0",
"has_message_feature": false,
"status": "UNKNOWN",
"created_at": "2020-08-30T15:55:19.467Z",
"updated_at": "2020-08-30T15:55:19.467Z"
},
{
"id": "d6ea610f-1e33-4c08-89a3-1c8be2cc45f9",
"pod_id": null,
"name": "bluetooth",
"selector": "bluetooth",
"version": "0.1.0",
"has_message_feature": false,
"status": "LOADING",
"created_at": "2020-09-02T12:35:32.763Z",
"updated_at": "2020-10-18T09:28:14.935Z"
}
],
"get /api/v1/session": [
{
"id": "4b249694-661b-4c48-afb5-924bbedcee63",
Expand Down
38 changes: 38 additions & 0 deletions front/src/config/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,7 @@
"systemTab": "System",
"gatewayTab": "Gladys Plus",
"backupTab": "Backups",
"serviceTab": "Services",
"billingTab": "Billing",
"gatewayUsersTab": "Users",
"gatewayOpenApiTab": "Open API"
Expand All @@ -846,6 +847,43 @@
"unknowDevice": "Unknow device",
"apiKey": "API Key"
},
"servicesSettings": {
"title": "Services",
"selector": "Selector: {{key}}",
"integrationLinkTitle": "Go to integration page",
"status": {
"title": "Status",
"UNKNOWN": {
"title": "Unknown",
"detail": "Service not found"
},
"DISABLED": {
"title": "Disabled",
"detail": "Service disabled"
},
"ENABLED": {
"title": "Enabled",
"detail": "Service enabled"
},
"RUNNING": {
"title": "Running",
"detail": "Service running"
},
"STOPPED": {
"title": "Stopped",
"detail": "Service stopped by user"
},
"ERROR": {
"title": "Issued",
"detail": "Service might not be well configured"
},
"LOADING": {
"title": "Error",
"detail": "Service failed to start, please check logs"
}
},
"action": "Action"
},
"forgotPassword": {
"title": "Gladys Assistant",
"cardTitle": "Recover your password",
Expand Down
38 changes: 38 additions & 0 deletions front/src/config/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,7 @@
"systemTab": "Système",
"gatewayTab": "Gladys Plus",
"backupTab": "Sauvegardes",
"serviceTab": "Services",
"billingTab": "Facturation",
"gatewayUsersTab": "Utilisateurs",
"gatewayOpenApiTab": "Open API"
Expand All @@ -846,6 +847,43 @@
"unknowDevice": "Appareil inconnu",
"apiKey": "Clé API"
},
"servicesSettings": {
"title": "Services",
"selector": "Sélecteur : {{key}}",
"integrationLinkTitle": "Aller à la page de l'intégration",
"status": {
"title": "Status",
"UNKNOWN": {
"title": "Inconnu",
"detail": "Service non trouvé"
},
"DISABLED": {
"title": "Désactivé",
"detail": "Service désactivé"
},
"ENABLED": {
"title": "Activé",
"detail": "Service activé"
},
"RUNNING": {
"title": "Démarré",
"detail": "Service en cours d'exécution"
},
"STOPPED": {
"title": "Arrêté",
"detail": "Service arrêté par un utilsateur"
},
"ERROR": {
"title": "Problèmes",
"detail": "Service probablement mal configuré"
},
"LOADING": {
"title": "Erreur",
"detail": "Service impossible a démarrer, consultez les logs"
}
},
"action": "Action"
},
"forgotPassword": {
"title": "Gladys Assistant",
"cardTitle": "Récupérez votre mot de passe",
Expand Down
11 changes: 11 additions & 0 deletions front/src/routes/settings/SettingsLayout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,17 @@ const DashboardSettings = ({ children, ...props }) => (
<Text id="settings.backupTab" />
</Link>

<Link
href="/dashboard/settings/service"
activeClassName="active"
class="list-group-item list-group-item-action d-flex align-items-center"
>
<span class="icon mr-3">
<i class="fe fe-grid" />
</span>
<Text id="settings.serviceTab" />
</Link>

<Link
href="/dashboard/settings/system"
activeClassName="active"
Expand Down
Loading

0 comments on commit 92a541c

Please sign in to comment.