mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-26 10:21:52 +00:00
better i18n checks, better action disabled, fix cert download for ios
This commit is contained in:
@@ -215,7 +215,7 @@ export default class SuccessPage implements AfterViewInit {
|
||||
.getElementById('cert')
|
||||
?.setAttribute(
|
||||
'href',
|
||||
`data:application/x-x509-ca-cert;base64,${this.result!.rootCa}`,
|
||||
`data:application/octet-stream;base64,${this.result!.rootCa}`,
|
||||
)
|
||||
|
||||
const html = this.documentation?.nativeElement.innerHTML || ''
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// prettier-ignore
|
||||
export const ENGLISH = {
|
||||
export const ENGLISH: Record<string, number> = {
|
||||
'Change': 1, // verb
|
||||
'Update': 2, // verb
|
||||
'System': 4, // as in, system preferences
|
||||
@@ -680,4 +680,4 @@ export const ENGLISH = {
|
||||
'Installation Complete!': 714,
|
||||
'StartOS has been installed successfully.': 715,
|
||||
'Continue to Setup': 716,
|
||||
} as const
|
||||
}
|
||||
|
||||
@@ -13,6 +13,8 @@ export class i18nPipe implements PipeTransform {
|
||||
transform(englishKey: i18nKey | null | undefined | ''): string {
|
||||
englishKey = englishKey || ('' as i18nKey)
|
||||
|
||||
return this.i18n()?.[ENGLISH[englishKey]] || englishKey
|
||||
const id = ENGLISH[englishKey]
|
||||
|
||||
return (id !== undefined && this.i18n()?.[id]) || englishKey
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,21 @@ const INACTIVE: PrimaryStatus[] = [
|
||||
'backing-up',
|
||||
]
|
||||
|
||||
const ALLOWED_STATUSES: Record<T.AllowedStatuses, Set<string>> = {
|
||||
'only-running': new Set(['running']),
|
||||
'only-stopped': new Set(['stopped']),
|
||||
any: new Set([
|
||||
'running',
|
||||
'stopped',
|
||||
'restarting',
|
||||
'restoring',
|
||||
'stopping',
|
||||
'starting',
|
||||
'backing-up',
|
||||
'task-required',
|
||||
]),
|
||||
}
|
||||
|
||||
@Component({
|
||||
template: `
|
||||
@if (package(); as pkg) {
|
||||
@@ -92,8 +107,9 @@ export default class ServiceActionsRoute {
|
||||
const specialGroup = Object.values(pkg.actions).some(a => !!a.group)
|
||||
? 'Other'
|
||||
: 'General'
|
||||
const status = renderPkgStatus(pkg).primary
|
||||
return {
|
||||
status: renderPkgStatus(pkg).primary,
|
||||
status,
|
||||
icon: pkg.icon,
|
||||
manifest: getManifest(pkg),
|
||||
actions: Object.entries(pkg.actions)
|
||||
@@ -102,6 +118,13 @@ export default class ServiceActionsRoute {
|
||||
...action,
|
||||
id,
|
||||
group: action.group || specialGroup,
|
||||
visibility: ALLOWED_STATUSES[action.allowedStatuses].has(
|
||||
status,
|
||||
)
|
||||
? action.visibility
|
||||
: ({
|
||||
disabled: `${this.i18n.transform('Action can only be executed when service is')} ${this.i18n.transform(action.allowedStatuses === 'only-running' ? 'Running' : 'Stopped')?.toLowerCase()}`,
|
||||
} as T.ActionVisibility),
|
||||
}))
|
||||
.sort((a, b) => {
|
||||
if (a.group === specialGroup && b.group !== specialGroup)
|
||||
|
||||
@@ -3,7 +3,6 @@ import {
|
||||
DialogService,
|
||||
ErrorService,
|
||||
i18nKey,
|
||||
i18nPipe,
|
||||
LoadingService,
|
||||
} from '@start9labs/shared'
|
||||
import { PolymorpheusComponent } from '@taiga-ui/polymorpheus'
|
||||
@@ -16,21 +15,6 @@ import { ActionSuccessPage } from 'src/app/routes/portal/routes/services/modals/
|
||||
import { ApiService } from 'src/app/services/api/embassy-api.service'
|
||||
import { FormDialogService } from 'src/app/services/form-dialog.service'
|
||||
|
||||
const allowedStatuses = {
|
||||
'only-running': new Set(['running']),
|
||||
'only-stopped': new Set(['stopped']),
|
||||
any: new Set([
|
||||
'running',
|
||||
'stopped',
|
||||
'restarting',
|
||||
'restoring',
|
||||
'stopping',
|
||||
'starting',
|
||||
'backing-up',
|
||||
'task-required',
|
||||
]),
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
@@ -40,58 +24,32 @@ export class ActionService {
|
||||
private readonly errorService = inject(ErrorService)
|
||||
private readonly loader = inject(LoadingService)
|
||||
private readonly formDialog = inject(FormDialogService)
|
||||
private readonly i18n = inject(i18nPipe)
|
||||
|
||||
async present(data: PackageActionData) {
|
||||
const { pkgInfo, actionInfo } = data
|
||||
|
||||
if (
|
||||
allowedStatuses[actionInfo.metadata.allowedStatuses].has(pkgInfo.status)
|
||||
) {
|
||||
if (actionInfo.metadata.hasInput) {
|
||||
this.formDialog.open<PackageActionData>(ActionInputModal, {
|
||||
label: actionInfo.metadata.name as i18nKey,
|
||||
data,
|
||||
})
|
||||
} else {
|
||||
if (actionInfo.metadata.warning) {
|
||||
this.dialog
|
||||
.openConfirm({
|
||||
label: 'Warning',
|
||||
size: 's',
|
||||
data: {
|
||||
no: 'Cancel',
|
||||
yes: 'Run',
|
||||
content: actionInfo.metadata.warning as i18nKey,
|
||||
},
|
||||
})
|
||||
.pipe(filter(Boolean))
|
||||
.subscribe(() => this.execute(pkgInfo.id, null, actionInfo.id))
|
||||
} else {
|
||||
this.execute(pkgInfo.id, null, actionInfo.id)
|
||||
}
|
||||
}
|
||||
if (actionInfo.metadata.hasInput) {
|
||||
this.formDialog.open<PackageActionData>(ActionInputModal, {
|
||||
label: actionInfo.metadata.name as i18nKey,
|
||||
data,
|
||||
})
|
||||
} else {
|
||||
const statuses = [...allowedStatuses[actionInfo.metadata.allowedStatuses]]
|
||||
const last = statuses.pop()
|
||||
let statusesStr = statuses.join(', ')
|
||||
if (statuses.length) {
|
||||
if (statuses.length > 1) {
|
||||
// oxford comma
|
||||
statusesStr += ','
|
||||
}
|
||||
statusesStr += ` or ${last}`
|
||||
} else if (last) {
|
||||
statusesStr = last
|
||||
if (actionInfo.metadata.warning) {
|
||||
this.dialog
|
||||
.openConfirm({
|
||||
label: 'Warning',
|
||||
size: 's',
|
||||
data: {
|
||||
no: 'Cancel',
|
||||
yes: 'Run',
|
||||
content: actionInfo.metadata.warning as i18nKey,
|
||||
},
|
||||
})
|
||||
.pipe(filter(Boolean))
|
||||
.subscribe(() => this.execute(pkgInfo.id, null, actionInfo.id))
|
||||
} else {
|
||||
this.execute(pkgInfo.id, null, actionInfo.id)
|
||||
}
|
||||
|
||||
this.dialog
|
||||
.openAlert(
|
||||
`${this.i18n.transform('Action can only be executed when service is')} ${statusesStr}` as i18nKey,
|
||||
{ label: 'Forbidden' },
|
||||
)
|
||||
.pipe(filter(Boolean))
|
||||
.subscribe()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user