Skip to content

Commit

Permalink
admin points
Browse files Browse the repository at this point in the history
  • Loading branch information
kdudkov committed Jan 14, 2025
1 parent 775a5b7 commit f131cff
Show file tree
Hide file tree
Showing 14 changed files with 304 additions and 191 deletions.
3 changes: 3 additions & 0 deletions .changes/unreleased/Added-20250114-221930.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Added
body: Points page in admin interface
time: 2025-01-14T22:19:30.61112+03:00
3 changes: 3 additions & 0 deletions .changes/unreleased/Fixed-20250114-221952.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Fixed
body: MissioChange for resources
time: 2025-01-14T22:19:52.861533+03:00
77 changes: 50 additions & 27 deletions cmd/goatak_server/admin_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,28 +47,31 @@ func NewAdminAPI(app *App, addr string, webtakRoot string) *AdminAPI {
staticfiles.Embed(api.f)

api.f.Get("/", getIndexHandler())
api.f.Get("/points", getPointsHandler())
api.f.Get("/units", getUnitsHandler())
api.f.Get("/map", getMapHandler())
api.f.Get("/missions", getMissionsPageHandler())
api.f.Get("/packages", getMPPageHandler()).Name("admin_files")
api.f.Get("/config", getConfigHandler(app))
api.f.Get("/connections", getConnHandler(app))
api.f.Get("/files", getFilesPage()).Name("admin_files")
api.f.Get("/points", getPointsPage())

api.f.Get("/unit", getUnitsHandler(app))
api.f.Get("/unit/:uid/track", getUnitTrackHandler(app))
api.f.Delete("/unit/:uid", deleteItemHandler(app))
api.f.Get("/message", getMessagesHandler(app))
api.f.Get("/api/config", getConfigHandler(app))
api.f.Get("/api/connections", getApiConnHandler(app))

api.f.Get("/api/unit", getApiUnitsHandler(app))
api.f.Get("/api/unit/:uid/track", getApiUnitTrackHandler(app))
api.f.Delete("/api/unit/:uid", deleteItemHandler(app))
api.f.Get("/api/message", getMessagesHandler(app))

api.f.Get("/ws", getWsHandler(app))
api.f.Get("/takproto/1", getTakWsHandler(app))
api.f.Post("/cot", getCotPostHandler(app))
api.f.Post("/cot_xml", getCotXMLPostHandler(app))

api.f.Get("/mp", getAllMissionPackagesHandler(app))
api.f.Get("/mp/:id", getPackageHandler(app))
api.f.Get("/mp/delete/:id", getPackageDeleteHandler(app))
api.f.Get("/api/file", getApiFilesHandler(app))
api.f.Get("/api/file/:id", GetApiFileHandler(app))
api.f.Get("/api/file/delete/:id", getApiFileDeleteHandler(app))
api.f.Get("/api/point", getApiPointsHandler(app))

api.f.Get("/mission", getAllMissionHandler(app))
api.f.Get("/api/mission", getApiAllMissionHandler(app))

if webtakRoot != "" {
api.f.Static("/webtak", webtakRoot)
Expand Down Expand Up @@ -102,15 +105,15 @@ func getIndexHandler() fiber.Handler {
}
}

func getPointsHandler() fiber.Handler {
func getUnitsHandler() fiber.Handler {
return func(ctx *fiber.Ctx) error {
data := map[string]any{
"theme": "auto",
"page": " points",
"js": []string{"util.js", "points.js"},
"page": " units",
"js": []string{"util.js", "units.js"},
}

return ctx.Render("templates/points", data, "templates/menu", "templates/header")
return ctx.Render("templates/units", data, "templates/menu", "templates/header")
}
}

Expand All @@ -137,15 +140,27 @@ func getMissionsPageHandler() fiber.Handler {
}
}

func getMPPageHandler() fiber.Handler {
func getFilesPage() fiber.Handler {
return func(ctx *fiber.Ctx) error {
data := map[string]any{
"theme": "auto",
"page": " mp",
"js": []string{"mp.js"},
"page": " files",
"js": []string{"files.js"},
}

return ctx.Render("templates/mp", data, "templates/menu", "templates/header")
return ctx.Render("templates/files", data, "templates/menu", "templates/header")
}
}

func getPointsPage() fiber.Handler {
return func(ctx *fiber.Ctx) error {
data := map[string]any{
"theme": "auto",
"page": " points",
"js": []string{"points.js"},
}

return ctx.Render("templates/points", data, "templates/menu", "templates/header")
}
}

Expand All @@ -163,7 +178,7 @@ func getConfigHandler(app *App) fiber.Handler {
}
}

func getUnitsHandler(app *App) fiber.Handler {
func getApiUnitsHandler(app *App) fiber.Handler {
return func(ctx *fiber.Ctx) error {
return ctx.JSON(getUnits(app))
}
Expand All @@ -187,7 +202,7 @@ func getMetricsHandler() fiber.Handler {
return adaptor.HTTPHandler(handler)
}

func getUnitTrackHandler(app *App) fiber.Handler {
func getApiUnitTrackHandler(app *App) fiber.Handler {
return func(ctx *fiber.Ctx) error {
uid := ctx.Params("uid")

Expand All @@ -213,7 +228,7 @@ func deleteItemHandler(app *App) fiber.Handler {
}
}

func getConnHandler(app *App) fiber.Handler {
func getApiConnHandler(app *App) fiber.Handler {
return func(ctx *fiber.Ctx) error {
conn := make([]*Connection, 0)

Expand Down Expand Up @@ -284,7 +299,7 @@ func getCotXMLPostHandler(app *App) fiber.Handler {
}
}

func getAllMissionHandler(app *App) fiber.Handler {
func getApiAllMissionHandler(app *App) fiber.Handler {
return func(ctx *fiber.Ctx) error {
data := app.dbm.MissionQuery().Full().Get()

Expand All @@ -298,15 +313,15 @@ func getAllMissionHandler(app *App) fiber.Handler {
}
}

func getAllMissionPackagesHandler(app *App) fiber.Handler {
func getApiFilesHandler(app *App) fiber.Handler {
return func(ctx *fiber.Ctx) error {
data := app.dbm.GetFiles()

return ctx.JSON(data)
}
}

func getPackageHandler(app *App) fiber.Handler {
func GetApiFileHandler(app *App) fiber.Handler {
return func(ctx *fiber.Ctx) error {
id, err := ctx.ParamsInt("id")

Expand Down Expand Up @@ -352,7 +367,7 @@ func getPackageHandler(app *App) fiber.Handler {
}
}

func getPackageDeleteHandler(app *App) fiber.Handler {
func getApiFileDeleteHandler(app *App) fiber.Handler {
return func(ctx *fiber.Ctx) error {
id, err := ctx.ParamsInt("id")

Expand All @@ -370,6 +385,14 @@ func getPackageDeleteHandler(app *App) fiber.Handler {
}
}

func getApiPointsHandler(app *App) fiber.Handler {
return func(ctx *fiber.Ctx) error {
data := app.dbm.GetPoints()

return ctx.JSON(data)
}
}

func getWsHandler(app *App) fiber.Handler {
return websocket.New(func(ws *websocket.Conn) {
name := uuid.NewString()
Expand Down
13 changes: 13 additions & 0 deletions cmd/goatak_server/database/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,19 @@ func (mm *DatabaseManager) GetFiles() []*model.Resource {
return m
}

func (mm *DatabaseManager) GetPoints() []*model.Point {
var m []*model.Point

err := mm.db.Order("created_at DESC").
Find(&m).Error

if errors.Is(err, gorm.ErrRecordNotFound) {
return nil
}

return m
}

func (mm *DatabaseManager) DeleteFile(id uint) {
mm.db.Where("id = ?", id).Delete(&model.Resource{})
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@
<div class="col">
<div v-if="current != null" class="overflow-auto">
<h3>{{ current.Name }}</h3>
<a class="btn btn-outline-primary" :href="'/mp/' + current.ID">download</a><br/>
<a class="btn btn-outline-primary" :href="'/api/file/' + current.ID">download</a><br/>
Scope: {{ current.Scope }}<br/>
UID: {{ current.UID }}<br/>
Hash: {{ current.Hash }}<br/>
MimeType: {{ current.MIMEType }}<br/>
Keywords: {{ current.Keywords }}<br/>
Author: {{ current.SubmissionUser }} {{ current.CreatorUID }}<br/>
Tool: {{ current.Tool }}<br/>
<a class="btn btn-outline-danger" :href="'/mp/delete/' + current.ID">delete</a><br/>
<img class="w-100" v-if="current.MIMEType.startsWith('image/')" :src="'/mp/' + current.ID"/>
<a class="btn btn-outline-danger" :href="'/api/file/delete/' + current.ID">delete</a><br/>
<img class="w-100" v-if="current.MIMEType.startsWith('image/')" :src="'/api/file/' + current.ID"/>
</div>
</div>
</div>
16 changes: 11 additions & 5 deletions cmd/goatak_server/templates/menu.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ <h5>GoATAK server</h5>
</a>
</li>
<li class="nav-item">
<a class="nav-link d-flex align-items-center gap-2 [[if eq .page " points"]]active[[end]]"
aria-current="page" href="/points">
Points
<a class="nav-link d-flex align-items-center gap-2 [[if eq .page " units"]]active[[end]]"
aria-current="page" href="/units">
Units
</a>
</li>
<li class="nav-item">
Expand All @@ -23,11 +23,17 @@ <h5>GoATAK server</h5>
</a>
</li>
<li class="nav-item">
<a class="nav-link d-flex align-items-center gap-2 [[if eq .page " mp"]]active[[end]]"
aria-current="page" href="/packages">
<a class="nav-link d-flex align-items-center gap-2 [[if eq .page " files"]]active[[end]]"
aria-current="page" href="/files">
Files
</a>
</li>
<li class="nav-item">
<a class="nav-link d-flex align-items-center gap-2 [[if eq .page " points"]]active[[end]]"
aria-current="page" href="/points">
Points
</a>
</li>
<li class="nav-item">
<a class="nav-link d-flex align-items-center gap-2" aria-current="page" href="/map">
Map
Expand Down
2 changes: 1 addition & 1 deletion cmd/goatak_server/templates/missions.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ <h5>Points</h5>
<h5>Files</h5>
<table class="table table-hover table-sm units">
<tr v-for="c in current.contents">
<td><a :href="'/mp/' + c.data?.uid">{{ c.data?.name }}</a></td>
<td><a :href="'/api/file/' + c.data?.uid">{{ c.data?.name }}</a></td>
<td>{{ c.data?.mimeType }}</td>
<td>{{ c.data?.size }}</td>
</tr>
Expand Down
125 changes: 17 additions & 108 deletions cmd/goatak_server/templates/points.html
Original file line number Diff line number Diff line change
@@ -1,111 +1,20 @@
<div class="row">
<div class="col">
<div class="overflow-auto">
<div class="alert alert-secondary info" role="alert" v-if="alert">
{{ alert }}
</div>
<div class="card mb-2">
<div class="card-header">Connections <span
class="badge rounded-pill bg-success">{{ connections.size }}</span></div>
<div class="card-body">
<table class="table table-hover table-sm units">
<tr>
<th>addr</th>
<th>UIDS</th>
<th>user</th>
<th>scope</th>
<th>ver</th>
<th>last seen</th>
</tr>
<tr v-for="c in all_conns">
<td>{{ c.addr }}</td>
<td>
<span v-for="(k, v) in c.uids">{{ k }}: {{ v }}</span>
</td>
<td>{{ c.user }}</td>
<td>{{ c.scope }}</td>
<td>{{ c.ver }}</td>
<td>{{ dt(c.last_seen) }}</td>
</tr>
</table>
</div>
</div>
<div class="card mb-2">
<div class="card-header">Contacts <span class="badge rounded-pill bg-success">{{ contactsNum() }}</span>
</div>
<div class="card-body">
<table class="table table-hover table-sm units">
<tr>
<th></th>
<th>callsign</th>
<th>scope</th>
<th>status</th>
<th>coords</th>
<th>TAK ver.</th>
</tr>
<tr v-for="u in byCategory('contact')">
<td><img :src="getImg(u, 18)"/></td>
<td>{{ u.callsign }}</td>
<td>{{ u.scope }}</td>
<td><span class="badge"
:class="u.status=='Online' ? 'text-bg-success' : 'text-bg-secondary'">
{{ u.status }}</span>
</td>
<td>{{ printCoords(u.lat, u.lon) }}</td>
<td>{{ u.tak_version }}</td>
</tr>
</table>
</div>
</div>
</div>
<table class="table table-hover table-sm">
<tr>
<th>Scope</th>
<th>UID</th>
<th>Callsign</th>
<th>Type</th>
<th>Coords</th>
</tr>
<tr v-for="p in all" @click="current = p">
<td>{{ p.Scope }}</td>
<td>{{ p.UID }}</td>
<td>{{ p.Callsign }}</td>
<td>{{ p.Type }}</td>
<td>{{ p.Lat }},{{ p.Lon }}</td>
</tr>
</table>
</div>
<div class="col">
<div class="card mb-2">
<div class="card-header">Units</div>
<div class="card-body">
<table class="table table-hover table-sm units">
<tr>
<th></th>
<th>type</th>
<th>callsign</th>
<th>coords</th>
<th>scope</th>
<th>stale time</th>
</tr>
<tr v-for="u in byCategory('unit')">
<td><img :src="getImg(u, 18)"/>
</td>
<td>{{ u.type }}</td>
<td>{{ u.callsign }}</td>
<td>{{ printCoords(u.lat, u.lon) }}</td>
<td>{{ u.scope }}</td>
<td>{{ dt(u.stale_time) }}</td>
</tr>
</table>
</div>
</div>
<div class="card mb-2">
<div class="card-header">Points</div>
<div class="card-body">
<table class="table table-hover table-sm units">
<tr>
<th></th>
<th>type</th>
<th>callsign</th>
<th>coords</th>
<th>scope</th>
<th>stale time</th>
</tr>
<tr v-for="u in byCategory('point')">
<td><img :src="getImg(u, 18)"/></td>
<td>{{ u.type }}</td>
<td>{{ u.callsign }}</td>
<td>{{ printCoords(u.lat, u.lon) }}</td>
<td>{{ u.scope }}</td>
<td>{{ dt(u.stale_time) }}</td>
</tr>
</table>
</div>
</div>
</div>
</div>
</div>
Loading

0 comments on commit f131cff

Please sign in to comment.