mirror of
https://github.com/seriousm4x/UpSnap.git
synced 2026-04-05 08:53:55 -04:00
define possible device.status values
This commit is contained in:
75
backend/migrations/1691946735_updated_devices.go
Normal file
75
backend/migrations/1691946735_updated_devices.go
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
package migrations
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
|
"github.com/pocketbase/dbx"
|
||||||
|
"github.com/pocketbase/pocketbase/daos"
|
||||||
|
m "github.com/pocketbase/pocketbase/migrations"
|
||||||
|
"github.com/pocketbase/pocketbase/models/schema"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
m.Register(func(db dbx.Builder) error {
|
||||||
|
dao := daos.New(db);
|
||||||
|
|
||||||
|
collection, err := dao.FindCollectionByNameOrId("z5lghx2r3tm45n1")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove
|
||||||
|
collection.Schema.RemoveField("qqvyfrex")
|
||||||
|
|
||||||
|
// add
|
||||||
|
new_status := &schema.SchemaField{}
|
||||||
|
json.Unmarshal([]byte(`{
|
||||||
|
"system": false,
|
||||||
|
"id": "qmiatdwa",
|
||||||
|
"name": "status",
|
||||||
|
"type": "select",
|
||||||
|
"required": false,
|
||||||
|
"unique": false,
|
||||||
|
"options": {
|
||||||
|
"maxSelect": 1,
|
||||||
|
"values": [
|
||||||
|
"pending",
|
||||||
|
"online",
|
||||||
|
"offline"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}`), new_status)
|
||||||
|
collection.Schema.AddField(new_status)
|
||||||
|
|
||||||
|
return dao.SaveCollection(collection)
|
||||||
|
}, func(db dbx.Builder) error {
|
||||||
|
dao := daos.New(db);
|
||||||
|
|
||||||
|
collection, err := dao.FindCollectionByNameOrId("z5lghx2r3tm45n1")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// add
|
||||||
|
del_status := &schema.SchemaField{}
|
||||||
|
json.Unmarshal([]byte(`{
|
||||||
|
"system": false,
|
||||||
|
"id": "qqvyfrex",
|
||||||
|
"name": "status",
|
||||||
|
"type": "text",
|
||||||
|
"required": false,
|
||||||
|
"unique": false,
|
||||||
|
"options": {
|
||||||
|
"min": null,
|
||||||
|
"max": null,
|
||||||
|
"pattern": ""
|
||||||
|
}
|
||||||
|
}`), del_status)
|
||||||
|
collection.Schema.AddField(del_status)
|
||||||
|
|
||||||
|
// remove
|
||||||
|
collection.Schema.RemoveField("qmiatdwa")
|
||||||
|
|
||||||
|
return dao.SaveCollection(collection)
|
||||||
|
})
|
||||||
|
}
|
||||||
68
backend/migrations/1691946735_updated_users.go
Normal file
68
backend/migrations/1691946735_updated_users.go
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
package migrations
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
|
"github.com/pocketbase/dbx"
|
||||||
|
"github.com/pocketbase/pocketbase/daos"
|
||||||
|
m "github.com/pocketbase/pocketbase/migrations"
|
||||||
|
"github.com/pocketbase/pocketbase/models/schema"
|
||||||
|
"github.com/pocketbase/pocketbase/tools/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
m.Register(func(db dbx.Builder) error {
|
||||||
|
dao := daos.New(db);
|
||||||
|
|
||||||
|
collection, err := dao.FindCollectionByNameOrId("27do0wbcuyfmbmx")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
collection.ListRule = types.Pointer("@request.auth.id = id")
|
||||||
|
|
||||||
|
collection.ViewRule = types.Pointer("@request.auth.id = id")
|
||||||
|
|
||||||
|
collection.UpdateRule = types.Pointer("@request.auth.id = id")
|
||||||
|
|
||||||
|
collection.DeleteRule = types.Pointer("@request.auth.id = id")
|
||||||
|
|
||||||
|
// add
|
||||||
|
new_avatar := &schema.SchemaField{}
|
||||||
|
json.Unmarshal([]byte(`{
|
||||||
|
"system": false,
|
||||||
|
"id": "i1qnezoa",
|
||||||
|
"name": "avatar",
|
||||||
|
"type": "number",
|
||||||
|
"required": false,
|
||||||
|
"unique": false,
|
||||||
|
"options": {
|
||||||
|
"min": 0,
|
||||||
|
"max": 9
|
||||||
|
}
|
||||||
|
}`), new_avatar)
|
||||||
|
collection.Schema.AddField(new_avatar)
|
||||||
|
|
||||||
|
return dao.SaveCollection(collection)
|
||||||
|
}, func(db dbx.Builder) error {
|
||||||
|
dao := daos.New(db);
|
||||||
|
|
||||||
|
collection, err := dao.FindCollectionByNameOrId("27do0wbcuyfmbmx")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
collection.ListRule = nil
|
||||||
|
|
||||||
|
collection.ViewRule = nil
|
||||||
|
|
||||||
|
collection.UpdateRule = nil
|
||||||
|
|
||||||
|
collection.DeleteRule = nil
|
||||||
|
|
||||||
|
// remove
|
||||||
|
collection.Schema.RemoveField("i1qnezoa")
|
||||||
|
|
||||||
|
return dao.SaveCollection(collection)
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -121,21 +121,21 @@ func StartPocketBase(distDirFS fs.FS) {
|
|||||||
var permissionRec *models.Record
|
var permissionRec *models.Record
|
||||||
permissionRec, err := App.Dao().FindFirstRecordByFilter("permissions",
|
permissionRec, err := App.Dao().FindFirstRecordByFilter("permissions",
|
||||||
fmt.Sprintf("user.id = '%s'", userId))
|
fmt.Sprintf("user.id = '%s'", userId))
|
||||||
if err != nil {
|
if err != nil && err.Error() != "sql: no rows in result set" {
|
||||||
logger.Error.Println(err)
|
logger.Error.Println(err)
|
||||||
return err
|
return err
|
||||||
}
|
} else if permissionRec != nil {
|
||||||
|
|
||||||
permissionRec.Set("read", append(permissionRec.GetStringSlice("read"), deviceRec.Id))
|
permissionRec.Set("read", append(permissionRec.GetStringSlice("read"), deviceRec.Id))
|
||||||
permissionRec.Set("update", append(permissionRec.GetStringSlice("update"), deviceRec.Id))
|
permissionRec.Set("update", append(permissionRec.GetStringSlice("update"), deviceRec.Id))
|
||||||
permissionRec.Set("delete", append(permissionRec.GetStringSlice("delete"), deviceRec.Id))
|
permissionRec.Set("delete", append(permissionRec.GetStringSlice("delete"), deviceRec.Id))
|
||||||
permissionRec.Set("power", append(permissionRec.GetStringSlice("power"), deviceRec.Id))
|
permissionRec.Set("power", append(permissionRec.GetStringSlice("power"), deviceRec.Id))
|
||||||
|
|
||||||
if err := App.Dao().SaveRecord(permissionRec); err != nil {
|
if err := App.Dao().SaveRecord(permissionRec); err != nil {
|
||||||
logger.Error.Println(err)
|
logger.Error.Println(err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if e.Model.TableName() == "devices" || e.Model.TableName() == "ports" {
|
if e.Model.TableName() == "devices" || e.Model.TableName() == "ports" {
|
||||||
// refresh the device list on database events
|
// refresh the device list on database events
|
||||||
if err := refreshDeviceList(); err != nil {
|
if err := refreshDeviceList(); err != nil {
|
||||||
|
|||||||
@@ -16,7 +16,9 @@
|
|||||||
countdown();
|
countdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
$: if (device.status === 'online') {
|
$: if (device.status === 'pending' || device.status === '') {
|
||||||
|
hoverText = 'Pending';
|
||||||
|
} else if (device.status === 'online') {
|
||||||
if (device.shutdown_cmd === '') {
|
if (device.shutdown_cmd === '') {
|
||||||
hoverText = 'No shutdown command set';
|
hoverText = 'No shutdown command set';
|
||||||
} else if (!$isAdmin && !$permission.power?.includes(device.id)) {
|
} else if (!$isAdmin && !$permission.power?.includes(device.id)) {
|
||||||
@@ -77,7 +79,8 @@
|
|||||||
|
|
||||||
<li
|
<li
|
||||||
class="tooltip"
|
class="tooltip"
|
||||||
class:disabled={(device.status === 'online' && device.shutdown_cmd === '') ||
|
class:disabled={device.status === 'pending' ||
|
||||||
|
(device.status === 'online' && device.shutdown_cmd === '') ||
|
||||||
(!isAdmin && !$permission.power?.includes(device.id))}
|
(!isAdmin && !$permission.power?.includes(device.id))}
|
||||||
data-tip={hoverText}
|
data-tip={hoverText}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ export type Device = Record & {
|
|||||||
ip: string;
|
ip: string;
|
||||||
mac: string;
|
mac: string;
|
||||||
netmask: string;
|
netmask: string;
|
||||||
status: string;
|
status: 'pending' | 'online' | 'offline' | '';
|
||||||
ports: string[];
|
ports: string[];
|
||||||
link: URL;
|
link: URL;
|
||||||
wake_cron: string;
|
wake_cron: string;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ export type ScannedDevice = {
|
|||||||
mac: string;
|
mac: string;
|
||||||
mac_vendor: string;
|
mac_vendor: string;
|
||||||
netmask: string;
|
netmask: string;
|
||||||
|
status: 'pending' | 'online' | 'offline' | '';
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ScanResponse = {
|
export type ScanResponse = {
|
||||||
|
|||||||
Reference in New Issue
Block a user