This commit is contained in:
2018-03-29 11:09:32 +02:00
parent 7b685076c6
commit 546b4dbf5e
5 changed files with 0 additions and 221 deletions

View File

@ -1,11 +0,0 @@
package database
import (
"github.com/aerogo/aero"
"github.com/animenotifier/notify.moe/components"
)
// Get the dashboard.
func Get(ctx *aero.Context) string {
return ctx.HTML(components.Database(ctx.URI()))
}

View File

@ -1,37 +0,0 @@
component Database(url string)
//- EditorTabs(url)
//- .widget-form
//- .widget
//- h1.mountable Database search
//- .widget-section.mountable
//- label(for="data-type") Search
//- select#data-type.widget-ui-element(value="Anime")
//- option(value="Analytics") Analytics
//- option(value="Anime") Anime
//- option(value="AnimeList") AnimeList
//- option(value="Character") Character
//- option(value="Group") Group
//- option(value="Post") Post
//- option(value="Settings") Settings
//- option(value="SoundTrack") SoundTrack
//- option(value="Thread") Thread
//- option(value="User") User
//- option(value="Quote") Quote
//- .widget-section.mountable
//- label(for="field") where
//- input#field.widget-ui-element(type="text", placeholder="Field name (e.g. Title or Title.Canonical)")
//- .widget-section.mountable
//- label(for="field-value") is
//- input#field-value.widget-ui-element(type="text")
//- .buttons.mountable
//- button.action(data-action="searchDB", data-trigger="click")
//- Icon("search")
//- span Search
//- h3.text-center Results
//- #records

View File

@ -1,25 +0,0 @@
#records
horizontal-wrap
justify-content space-around
margin-top content-padding
.record
vertical
ui-element
padding 0.5rem 1rem
margin 0.5rem
.record-id
:before
content "ID: "
.record-view
//
.record-view-api
//
.record-count
text-align right
font-size 0.8rem
opacity 0.5

View File

@ -1,70 +0,0 @@
package database
import (
"net/http"
"github.com/aerogo/aero"
"github.com/aerogo/mirror"
"github.com/animenotifier/arn"
)
// QueryResponse ..
type QueryResponse struct {
Results []interface{} `json:"results"`
}
// Select ...
func Select(ctx *aero.Context) string {
dataTypeName := ctx.Get("data-type")
field := ctx.Get("field")
searchValue := ctx.Get("field-value")
// Empty values
if dataTypeName == "+" {
dataTypeName = ""
}
if field == "+" {
field = ""
}
if searchValue == "+" {
searchValue = ""
}
// Check empty parameters
if dataTypeName == "" || field == "" {
return ctx.Error(http.StatusBadRequest, "Not enough parameters", nil)
}
// Check data type parameter
_, found := arn.DB.Types()[dataTypeName]
if !found {
return ctx.Error(http.StatusBadRequest, "Invalid type", nil)
}
response := &QueryResponse{
Results: []interface{}{},
}
stream := arn.DB.All(dataTypeName)
process := func(obj interface{}) {
_, _, value, _ := mirror.GetField(obj, field)
if value.String() == searchValue {
response.Results = append(response.Results, obj)
}
}
for obj := range stream {
process(obj)
}
for _, obj := range response.Results {
mirror.GetField(obj, field)
}
return ctx.JSON(response)
}