Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Zwiterrion committed Jan 15, 2025
1 parent b699be1 commit a8e0e9d
Show file tree
Hide file tree
Showing 5 changed files with 248 additions and 464 deletions.
33 changes: 30 additions & 3 deletions otoroshi/app/next/models/Api.scala
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,33 @@ object ApiConsumerStatus {
override def name: String ="closed"
}
}

case class ApiBackend(id: String, name: String, backend: NgBackend)

object ApiBackend {
val _fmt: Format[ApiBackend] = new Format[ApiBackend] {

override def reads(json: JsValue): JsResult[ApiBackend] = Try {
ApiBackend(
id = json.select("id").as[String],
name = json.select("name").as[String],
backend = json.select("backend").as(NgBackend.fmt)
)
} match {
case Failure(ex) =>
ex.printStackTrace()
JsError(ex.getMessage)
case Success(value) => JsSuccess(value)
}

override def writes(o: ApiBackend): JsValue = Json.obj(
"id" -> o.id,
"name" -> o.name,
"backend" -> NgBackend.fmt.writes(o.backend)
)
}
}

case class ApiBackendClient(name: String, client: NgClientConfig)

object ApiBackendClient {
Expand Down Expand Up @@ -514,7 +541,7 @@ case class Api(
state: ApiState,
blueprint: ApiBlueprint,
routes: Seq[ApiRoute],
backends: Seq[NgBackend],
backends: Seq[ApiBackend],
flows: Seq[ApiFlows],
clients: Seq[ApiBackendClient],
documentation: Option[ApiDocumentation],
Expand Down Expand Up @@ -553,7 +580,7 @@ object Api {
"state" -> o.state.name,
"blueprint" -> o.blueprint.name,
"routes" -> o.routes.map(ApiRoute._fmt.writes),
"backends" -> o.backends.map(NgBackend.fmt.writes),
"backends" -> o.backends.map(ApiBackend._fmt.writes),
"flows" -> o.flows.map(ApiFlows._fmt.writes),
"clients" -> o.clients.map(ApiBackendClient._fmt.writes),
"documentation" -> o.documentation.map(ApiDocumentation._fmt.writes),
Expand Down Expand Up @@ -591,7 +618,7 @@ object Api {
.getOrElse(Seq.empty),
backends = (json \ "backends")
.asOpt[Seq[JsValue]]
.map(_.flatMap(v => NgBackend.fmt.reads(v).asOpt))
.map(_.flatMap(v => ApiBackend._fmt.reads(v).asOpt))
.getOrElse(Seq.empty),
flows = (json \ "flows")
.asOpt[Seq[JsValue]]
Expand Down
8 changes: 5 additions & 3 deletions otoroshi/javascript/src/pages/ApiEditor/Sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ export default (props) => {

const currentTab = location.pathname.split('/').slice(-1)[0];

const noneTabIsActive = !LINKS().find(r => r.tab === currentTab)

const isActive = (tab) => {
const params = new URLSearchParams(window.location.search);
const queryTab = params.get('tab');
if (tab === 'informations' && noneTabIsActive)
return 'active'

return currentTab === tab || queryTab === tab ? 'active' : '';
return currentTab === tab ? 'active' : null
};

if (location.pathname.endsWith('/new')) return null;
Expand Down
Loading

0 comments on commit a8e0e9d

Please sign in to comment.