Skip to content

Commit ed1763c

Browse files
committed
feat(ui): improve alerts
1 parent 42348be commit ed1763c

File tree

8 files changed

+104
-35
lines changed

8 files changed

+104
-35
lines changed

api/router.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func Route(
113113
taskController := projects.NewTaskController(ansibleTaskRepo)
114114
rolesController := proApi.NewRolesController(store)
115115
templateController := projects.NewTemplateController(store, store)
116-
systmInfoController := NewSystemInfoController()
116+
systemInfoController := NewSystemInfoController(subscriptionService)
117117

118118
r := mux.NewRouter()
119119
r.NotFoundHandler = http.HandlerFunc(servePublic)
@@ -185,7 +185,7 @@ func Route(
185185
authenticatedAPI := r.PathPrefix(webPath + "api").Subrouter()
186186
authenticatedAPI.Use(StoreMiddleware, JSONMiddleware, authentication)
187187

188-
authenticatedAPI.Path("/info").HandlerFunc(systmInfoController.GetSystemInfo).Methods("GET", "HEAD")
188+
authenticatedAPI.Path("/info").HandlerFunc(systemInfoController.GetSystemInfo).Methods("GET", "HEAD")
189189

190190
authenticatedAPI.Path("/subscription").HandlerFunc(subscriptionController.Activate).Methods("POST")
191191
authenticatedAPI.Path("/subscription").HandlerFunc(subscriptionController.GetSubscription).Methods("GET")

api/system_info.go

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package api
22

33
import (
4+
"errors"
45
"net/http"
56

67
"github.com/semaphoreui/semaphore/api/helpers"
@@ -15,8 +16,10 @@ type SystemInfoController struct {
1516
subscriptionService pro_interfaces.SubscriptionService
1617
}
1718

18-
func NewSystemInfoController() *SystemInfoController {
19-
return &SystemInfoController{}
19+
func NewSystemInfoController(subscriptionService pro_interfaces.SubscriptionService) *SystemInfoController {
20+
return &SystemInfoController{
21+
subscriptionService,
22+
}
2023
}
2124

2225
func (c *SystemInfoController) GetSystemInfo(w http.ResponseWriter, r *http.Request) {
@@ -47,20 +50,39 @@ func (c *SystemInfoController) GetSystemInfo(w http.ResponseWriter, r *http.Requ
4750
return
4851
}
4952

53+
var plan string
54+
5055
token, err := c.subscriptionService.GetToken()
56+
57+
if errors.Is(err, db.ErrNotFound) {
58+
err = nil
59+
}
60+
5161
if err != nil {
5262
log.WithError(err).Error("Failed to get subscription plan")
5363
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
5464
return
5565
}
5666

67+
switch {
68+
case errors.Is(err, db.ErrNotFound):
69+
err = nil
70+
plan = ""
71+
case err != nil:
72+
log.WithError(err).Error("Failed to get subscription plan")
73+
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
74+
return
75+
default:
76+
plan = token.Plan
77+
}
78+
5779
body := map[string]any{
5880
"version": util.Version(),
5981
"ansible": util.AnsibleVersion(),
6082
"web_host": util.Config.WebHost,
6183
"use_remote_runner": util.Config.UseRemoteRunner,
6284
"auth_methods": authMethods,
63-
"premium_features": proFeatures.GetFeatures(user, token.Plan),
85+
"premium_features": proFeatures.GetFeatures(user, plan),
6486
"git_client": util.Config.GitClientId,
6587
"schedule_timezone": timezone,
6688
"teams": util.Config.Teams,

web/src/assets/scss/components.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,13 @@
2020

2121
.CodeMirror {
2222
border-radius: 5px !important;
23+
}
24+
25+
.PageAlert {
26+
border-radius: 0;
27+
.v-alert__content {
28+
display: flex;
29+
justify-content: space-between;
30+
align-items: center;
31+
}
2332
}

web/src/components/SubscriptionForm.vue

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,32 @@
5959
dense
6060
></v-textarea>
6161

62-
<v-btn
63-
@click="save"
64-
style="width: 100%; margin-top: -5px;"
65-
color="primary"
66-
:disabled="formSaving"
67-
>
68-
<v-progress-circular
69-
v-if="formSaving"
70-
indeterminate
71-
color="white"
72-
:size="24"
73-
></v-progress-circular>
74-
<span v-else>Activate new key</span>
75-
</v-btn>
62+
<v-row>
63+
<v-col>
64+
<v-btn
65+
@click="save"
66+
style="width: 100%;"
67+
color="primary"
68+
:disabled="formSaving"
69+
>
70+
<v-progress-circular
71+
v-if="formSaving"
72+
indeterminate
73+
color="white"
74+
:size="24"
75+
></v-progress-circular>
76+
<span v-else>Activate key</span>
77+
</v-btn>
78+
</v-col>
79+
<v-col>
80+
<v-btn
81+
style="width: 100%;"
82+
color="primary"
83+
:disabled="formSaving"
84+
>Buy Pro</v-btn>
85+
</v-col>
86+
</v-row>
87+
7688
</div>
7789

7890
<v-card

web/src/lang/en.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ export default {
304304
foss_runners_limited: 'The open-source version has limited functionality; full functionality is in the <b>PRO</b> version.',
305305
learn_more_about_pro: 'Learn more',
306306
upgrade_to_pro: 'Upgrade',
307-
contact_admin_to_upgrade: 'Contact your Semaphore administrator to upgrade to PRO.',
307+
contact_admin_to_upgrade: 'Contact your admin to activate PRO features.',
308308

309309
projectRestoreResult: 'Project restore results',
310310
projectWithNameRestored: 'Project {projectName} successfully restored.',

web/src/views/Roles.vue

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
<v-toolbar-title>{{ $t('Roles') }}</v-toolbar-title>
3838
<v-spacer></v-spacer>
3939
<v-btn
40+
:disabled="!premiumFeatures.custom_roles_management"
4041
color="primary"
4142
@click="editItem('new')"
4243
>{{ $t('newRole') }}</v-btn>
@@ -46,6 +47,29 @@
4647

4748
<v-divider style="margin-top: -1px;"/>
4849

50+
<v-alert
51+
v-if="!premiumFeatures.custom_roles_management"
52+
text
53+
color="amber darken-3"
54+
class="PageAlert"
55+
>
56+
<span class="mr-1" v-html="$t('roles_only_enterprise')"></span>
57+
58+
<v-btn
59+
dark
60+
depressed
61+
v-if="isAdmin"
62+
color="amber darken-3"
63+
href="https://semaphoreui.com/pro#secret_storages"
64+
>
65+
{{ $t('upgrade_to_pro') }}
66+
</v-btn>
67+
68+
<span v-else style="font-weight: bold;">
69+
{{ $t('contact_admin_to_upgrade') }}
70+
</span>
71+
</v-alert>
72+
4973
<v-data-table
5074
:headers="headers"
5175
:items="items"
@@ -101,6 +125,7 @@ export default {
101125
mixins: [ItemListPageBase],
102126
103127
props: {
128+
premiumFeatures: Object,
104129
projectId: Number,
105130
systemInfo: Object,
106131
},

web/src/views/Runners.vue

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
<code
6666
class="px-2 py-3 mt-2"
6767
style="background: gray; color: white; display: block; font-size: 14px;"
68-
>{{ (newRunner || {private_key: ''}).private_key.substring(0, 90) + '...' }}</code>
68+
>{{ (newRunner || { private_key: '' }).private_key.substring(0, 90) + '...' }}</code>
6969

7070
<v-btn
7171
style="position: absolute; right: 10px; top: 2px;"
@@ -95,7 +95,7 @@
9595
<v-tab key="docker">Docker</v-tab>
9696
</v-tabs>
9797

98-
<v-divider style="margin-top: -1px;"/>
98+
<v-divider style="margin-top: -1px;" />
9999

100100
<v-tabs-items v-model="usageTab">
101101
<v-tab-item key="config">
@@ -220,7 +220,7 @@
220220
</v-toolbar>
221221

222222
<v-btn
223-
v-else-if="premiumFeatures.project_runners"
223+
:disabled="!premiumFeatures.project_runners"
224224
style="position: absolute; right: 15px; top: 15px;"
225225
color="primary"
226226
@click="editItem('new')"
@@ -231,26 +231,23 @@
231231

232232
<v-alert
233233
v-if="projectId && !premiumFeatures.project_runners"
234-
type="info"
235234
text
236235
color="hsl(348deg, 86%, 61%)"
237-
style="border-radius: 0;"
236+
class="PageAlert"
238237
>
239238
<span v-html="$t('project_runners_only_pro')"></span>
240-
241239
<v-btn
240+
dark
242241
v-if="isAdmin"
243242
class="ml-2"
244243
color="hsl(348deg, 86%, 61%)"
245244
href="https://semaphoreui.com/pro#runners"
246245
>
247246
{{ $t('upgrade_to_pro') }}
248247
</v-btn>
249-
<v-else>
250-
<span>
251-
{{ $t('contact_admin_to_upgrade') }}
252-
</span>
253-
</v-else>
248+
<span v-else style="font-weight: bold;">
249+
{{ $t('contact_admin_to_upgrade') }}
250+
</span>
254251
</v-alert>
255252

256253
<v-alert

web/src/views/project/SecretStorages.vue

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,20 +96,24 @@
9696

9797
<v-alert
9898
v-if="!premiumFeatures.secret_storage_management"
99-
type="info"
10099
text
101100
color="hsl(348deg, 86%, 61%)"
102-
style="border-radius: 0;"
101+
class="PageAlert"
103102
>
104-
<span v-html="$t('secret_storage_only_pro')"></span>
103+
<span class="mr-1" v-html="$t('secret_storage_only_pro')"></span>
105104

106105
<v-btn
107-
class="ml-2"
106+
dark
107+
v-if="isAdmin"
108108
color="hsl(348deg, 86%, 61%)"
109109
href="https://semaphoreui.com/pro#secret_storages"
110110
>
111111
{{ $t('upgrade_to_pro') }}
112112
</v-btn>
113+
114+
<span v-else style="font-weight: bold;">
115+
{{ $t('contact_admin_to_upgrade') }}
116+
</span>
113117
</v-alert>
114118

115119
<v-data-table

0 commit comments

Comments
 (0)