Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/controller/application/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package application

import (
"context"
"time"

"github.com/cloudness-io/cloudness/app/controller/gitpublic"
"github.com/cloudness-io/cloudness/app/controller/server"
Expand Down Expand Up @@ -112,6 +113,7 @@ func (c *Controller) updateWithoutTx(ctx context.Context, dto *createOrUpdateDto
return nil, err
}

application.Updated = time.Now().UTC().UnixMilli()
application, err = c.applicationStore.UpdateSpec(ctx, application)
if err != nil {
return nil, err
Expand Down
20 changes: 20 additions & 0 deletions app/controller/application/general.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package application

import (
"context"

"github.com/cloudness-io/cloudness/types"
)

type UpdateIconInput struct {
Icon string `json:"icon"`
}

func (c *Controller) UpdateIcon(ctx context.Context, application *types.Application, in *UpdateIconInput) (*types.Application, error) {
application.Spec.Icon = in.Icon
err := application.UpdateSpecJSON()
if err != nil {
return nil, err
}
return c.applicationStore.UpdateSpec(ctx, application)
}
1 change: 1 addition & 0 deletions app/router/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ func setupApplication(r chi.Router, appCtx context.Context, envCtrl *environment
//Inject application here
r.Use(middlewareinject.InjectApplication(appCtrl))
r.Get("/", handlerapplication.HandleListDeployments(appCtrl, deploymentCtrl))
r.Patch("/icon", handlerapplication.HandleUpdateIcon(appCtrl))
r.Get("/deployments", handlerapplication.HandleListDeployments(appCtrl, deploymentCtrl))
r.Get("/settings", handlerapplication.HandleGetSettings(appCtrl, ghAppCtrl))
r.Patch("/settings", handlerapplication.HandleUpdateSettings(appCtrl, ghAppCtrl))
Expand Down
12 changes: 11 additions & 1 deletion app/services/spec/input_mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (s *Service) ToApplication(ctx context.Context, in *types.ApplicationInput,
}

func (s *Service) ToGeneralSettings(in *types.ApplicationInput, application *types.Application, spec *types.ApplicationSpec) {
var name, description string
var name, description, icon string
//Name
if in.Name != "" {
name = in.Name
Expand All @@ -117,8 +117,18 @@ func (s *Service) ToGeneralSettings(in *types.ApplicationInput, application *typ
description = spec.Description
}

//Icon
if in.Icon != "" {
icon = in.Icon
} else if application.Spec.Icon != "" {
icon = application.Spec.Icon
} else {
icon = spec.Icon
}

spec.Name = name
spec.Description = description
spec.Icon = icon
}

func (s *Service) ToBuildConfigration(ctx context.Context, in *types.ApplicationInput, application *types.Application) (*types.BuildConfiguration, error) {
Expand Down
2 changes: 0 additions & 2 deletions app/store/database/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,6 @@ func (s *ApplicationStore) UpdateSpec(ctx context.Context, application *types.Ap
,application_deleted = :application_deleted
WHERE application_id = :application_id`

application.Updated = time.Now().UTC().UnixMilli()

return s.update(ctx, application, applicationUpdate)
}

Expand Down
3 changes: 3 additions & 0 deletions app/utils/routes/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ const (

AppNav = "/nav"

//General Header
AppIcon = "icon"

AppSourceGithub = "source/github"
AppSourceGitPublic = "source/git-public"
AppSourceRegistry = "source/registry"
Expand Down
37 changes: 37 additions & 0 deletions app/web/handler/application/general.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package application

import (
"encoding/json"
"net/http"

"github.com/cloudness-io/cloudness/app/controller/application"
"github.com/cloudness-io/cloudness/app/request"
"github.com/cloudness-io/cloudness/app/utils/routes"
"github.com/cloudness-io/cloudness/app/web/render"

"github.com/rs/zerolog/log"
)

func HandleUpdateIcon(appCtrl *application.Controller) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()

in := new(application.UpdateIconInput)
if err := json.NewDecoder(r.Body).Decode(in); err != nil {
log.Ctx(ctx).Error().Err(err).Msg("Error decoding request body")
render.ToastError(ctx, w, err)
return
}

app, _ := request.ApplicationFrom(ctx)

_, err := appCtrl.UpdateIcon(ctx, app, in)
if err != nil {
log.Ctx(ctx).Error().Err(err).Msg("Error updating icon")
render.ToastError(ctx, w, err)
return
}

render.Redirect(w, routes.ApplicationCtx(ctx))
}
}
1 change: 1 addition & 0 deletions app/web/handler/create/oneclick.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/cloudness-io/cloudness/app/controller/template"
"github.com/cloudness-io/cloudness/app/web/render"
"github.com/cloudness-io/cloudness/app/web/views/components/vcreate"

"github.com/rs/zerolog/log"
)

Expand Down
55 changes: 52 additions & 3 deletions app/web/views/components/vapplication/header.templ
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package vapplication

import (
"fmt"
"github.com/cloudness-io/cloudness/app/utils/routes"
"github.com/cloudness-io/cloudness/app/web/views/components/icons"
"github.com/cloudness-io/cloudness/app/web/views/components/vfavorite"
"github.com/cloudness-io/cloudness/app/web/views/shared"
Expand All @@ -9,9 +11,25 @@ import (

templ appHeader(app *types.Application) {
<header class="relative h-16 shrink-0 box-border pl-1 md:pl-4">
<div id="header-content" class="flex box-border h-full py-2">
<span id="header-logo" class="flex grow shrink-0 basis-auto items-center justify-center mr-2 relative">
@shared.Icon(icons.ApplicationIcon, "overflow-hidden icon-2xl size-6")
<div id="header-content" class="flex box-border h-full py-2" x-data="{updateIconModel: false}">
@shared.Modal("updateIconModel", updateIconForm(app))
<span
id="header-logo"
class="flex grow shrink-0 basis-auto items-center justify-center mr-2 relative group"
x-on:click="updateIconModel = true"
>
if app.Spec.Icon != "" {
@shared.Icon(app.Spec.Icon, "overflow-hidden icon-2xl size-6")
} else {
@shared.Icon(icons.ApplicationIcon, "overflow-hidden icon-2xl size-6")
}
//show edit icon
<span
id="edit-icon"
class="absolute top-[0.2rem] right-[-0.5rem] hidden group-hover:block"
>
<i class={ icons.EditIcon, "icon-sm" }></i>
</span>
</span>
<div id="title" class="flex-auto w-full">
<div id="title-top-row" class="flex items-baseline gap-2">
Expand All @@ -33,3 +51,34 @@ templ appHeader(app *types.Application) {
</div>
</header>
}

templ updateIconForm(app *types.Application) {
<form class="flex flex-col gap-2" x-data={ fmt.Sprintf("{old:'%[1]s', icon:'%[1]s'}", app.Spec.Icon) }>
<h2 class="text-xl font-semibold">Update Icon</h2>
<p class="w-full max-w-full">
Icon should be an URL to an image file.
</p>
@shared.Input(&shared.InputProps{
Name: "icon",
Attrs: templ.Attributes{
"x-model": "icon",
},
})
<footer class="flex w-full">
<div class="ml-auto flex w-full gap-x-4 sm:w-auto sm:whitespace-nowrap">
<button type="button" class="button-neutral" x-on:click="updateIconModel= false">
Close
</button>
<button
type="submit"
class="button-primary"
:disabled="icon == old"
hx-patch={ routes.AppIcon }
hx-swap="none"
>
Update
</button>
</div>
</footer>
</form>
}
14 changes: 9 additions & 5 deletions app/web/views/components/vapplication/list.templ
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,21 @@ templ list(env *types.Environment, apps []*types.Application) {
<thead>
<tr class="text-tx-secondary">
<th class="whitespace-nowrap px-4 py-2 font-medium w-[35%]">Name</th>
<th class="whitespace-nowrap px-4 py-2 font-medium w-[35%] truncate overflow-hidden text-ellipsis">
Live
URL
</th>
<th class="whitespace-nowrap px-4 py-2 font-medium w-[35%] truncate overflow-hidden text-ellipsis">Live URL</th>
<th class="whitespace-nowrap px-4 py-2 font-medium w-[30%]">Status</th>
</tr>
</thead>
<tbody class="divide-y overflow-y-visible">
for _,app := range apps {
<tr class="hover:bg-secondary group cursor-pointer" hx-get={ routes.Application(env.UID, app.UID) }>
<td class="whitespace-nowrap px-4 py-2 hover:text-brand">{ app.Name }</td>
<td class="whitespace-nowrap px-4 py-2 hover:text-brand flex gap-x-1">
if app.Spec.Icon != "" {
@shared.Icon(app.Spec.Icon, "overflow-hidden")
} else {
@shared.Icon(icons.ApplicationIcon, "overflow-hidden")
}
{ app.Name }
</td>
<td
class="whitespace-nowrap px-4 py-2 max-w-40 sm:max-w-full truncate overflow-hidden
text-ellipsis"
Expand Down
4 changes: 2 additions & 2 deletions app/web/views/components/vproject/delete.templ
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ templ projectDelette(project *types.Project) {
Deleting this project will permanently delete all data components in the project for all environments.
This cannot be undone.
</div>
<buton type="button" class="button-danger w-20" x-on:click="projectDeleteModel = true">
<button type="button" class="button-danger w-20" x-on:click="projectDeleteModel = true">
Delete
</buton>
</button>
@shared.Modal("projectDeleteModel", deleteProjectForm(project))
</div>
}
Expand Down
1 change: 1 addition & 0 deletions app/web/views/shared/breadcrumb.templ
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ templ BreadCrumbDropdownList(items []*dto.BreadCrumbListItem) {
} else {
for _, item := range items {
<a
hx-push-url="true"
href={ item.Link }
class="block px-3 py-2 text-sm font-medium transition-colors hover:bg-secondary hover:text-brand"
>{ item.Name }</a>
Expand Down
6 changes: 5 additions & 1 deletion app/web/views/shared/icons.templ
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import (

templ Icon(icon string, class string) {
if strings.HasSuffix(icon, ".svg") {
<img class={ "size-4", class } src={ views.Asset(icon) }/>
if strings.HasPrefix(icon, "http://") || strings.HasPrefix(icon, "https://") {
<img class={ "size-4", class } src={ icon }/>
} else {
<img class={ "size-4", class } src={ views.Asset(icon) }/>
}
} else {
<i class={ icon, "icon-base", class }></i>
}
Expand Down
3 changes: 1 addition & 2 deletions types/application_input.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import (
)

type ApplicationInput struct {
Name string `json:"name"`
Description string `json:"description"`
*GeneralInput
*RegistryInput
*GitInput
*DeployInput
Expand Down
3 changes: 1 addition & 2 deletions types/application_spec_mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import (

func (s *ApplicationSpec) ToInput() *ApplicationInput {
return &ApplicationInput{
Name: s.Name,
Description: s.Description,
GeneralInput: s.ToGeneralInput(),
GitInput: s.ToGitInput(),
RegistryInput: s.ToRegistryInput(),
DeployInput: s.ToDeployInput(),
Expand Down
Loading