From 8b83cac9bda9e26e62c13a32b7311209f12e70c9 Mon Sep 17 00:00:00 2001 From: Buck Doyle Date: Thu, 9 Jul 2020 15:19:07 -0500 Subject: [PATCH] Add explicit this to templates (#8388) This is the result of running the no-implicit-this-codemod, some manual fixes, and the addition of a linting rule to prevent future ambiguity. --- ui/.template-lintrc.js | 1 + .../templates/allocations/allocation/fs.hbs | 18 +-- .../allocations/allocation/index.hbs | 98 ++++++------ .../allocations/allocation/task/fs.hbs | 18 +-- .../allocations/allocation/task/index.hbs | 68 ++++---- .../allocations/allocation/task/logs.hbs | 6 +- ui/app/templates/application.hbs | 18 +-- ui/app/templates/clients/client/index.hbs | 148 +++++++++--------- ui/app/templates/clients/client/monitor.hbs | 10 +- ui/app/templates/clients/index.hbs | 56 +++---- ui/app/templates/components/agent-monitor.hbs | 12 +- .../templates/components/allocation-row.hbs | 64 ++++---- .../templates/components/allocation-stat.hbs | 14 +- .../components/allocation-subnav.hbs | 4 +- .../templates/components/app-breadcrumbs.hbs | 4 +- .../components/attributes-section.hbs | 8 +- .../templates/components/attributes-table.hbs | 2 +- .../templates/components/client-node-row.hbs | 20 +-- ui/app/templates/components/client-subnav.hbs | 4 +- ui/app/templates/components/copy-button.hbs | 10 +- .../templates/components/distribution-bar.hbs | 10 +- ui/app/templates/components/drain-popover.hbs | 46 +++--- .../components/exec/task-contents.hbs | 6 +- .../components/exec/task-group-parent.hbs | 24 +-- .../components/forbidden-message.hbs | 10 +- .../templates/components/fs/breadcrumbs.hbs | 10 +- ui/app/templates/components/fs/browser.hbs | 26 +-- .../components/fs/directory-entry.hbs | 10 +- ui/app/templates/components/fs/file.hbs | 26 +-- ui/app/templates/components/fs/link.hbs | 14 +- ui/app/templates/components/gauge-chart.hbs | 18 +-- ui/app/templates/components/global-header.hbs | 2 +- .../components/global-search/match.hbs | 6 +- .../components/global-search/trigger.hbs | 4 +- ui/app/templates/components/gutter-menu.hbs | 28 ++-- ui/app/templates/components/image-file.hbs | 10 +- .../components/job-deployment-details.hbs | 6 +- .../templates/components/job-deployment.hbs | 16 +- .../job-deployment/deployment-allocations.hbs | 2 +- .../job-deployment/deployment-metrics.hbs | 20 +-- .../components/job-deployment/task-groups.hbs | 2 +- .../components/job-deployments-stream.hbs | 2 +- .../job-diff-fields-and-objects.hbs | 4 +- ui/app/templates/components/job-diff.hbs | 26 +-- ui/app/templates/components/job-editor.hbs | 46 +++--- .../templates/components/job-page/batch.hbs | 28 ++-- .../job-page/parameterized-child.hbs | 38 ++--- .../components/job-page/parameterized.hbs | 26 +-- .../components/job-page/parts/children.hbs | 18 +-- .../components/job-page/parts/error.hbs | 8 +- .../job-page/parts/latest-deployment.hbs | 32 ++-- .../job-page/parts/placement-failures.hbs | 4 +- .../job-page/parts/recent-allocations.hbs | 16 +- .../components/job-page/parts/summary.hbs | 2 +- .../components/job-page/parts/task-groups.hbs | 8 +- .../components/job-page/parts/title.hbs | 16 +- .../components/job-page/periodic-child.hbs | 32 ++-- .../components/job-page/periodic.hbs | 28 ++-- .../templates/components/job-page/service.hbs | 30 ++-- .../templates/components/job-page/system.hbs | 28 ++-- ui/app/templates/components/job-row.hbs | 20 +-- ui/app/templates/components/job-subnav.hbs | 2 +- ui/app/templates/components/job-version.hbs | 14 +- .../components/job-versions-stream.hbs | 4 +- ui/app/templates/components/json-viewer.hbs | 2 +- .../components/lifecycle-chart-row.hbs | 12 +- .../templates/components/lifecycle-chart.hbs | 12 +- ui/app/templates/components/line-chart.hbs | 42 ++--- .../templates/components/list-accordion.hbs | 6 +- .../list-accordion/accordion-body.hbs | 2 +- .../list-accordion/accordion-head.hbs | 6 +- .../templates/components/list-pagination.hbs | 22 +-- .../components/list-pagination/list-pager.hbs | 4 +- ui/app/templates/components/list-table.hbs | 6 +- .../components/list-table/sort-by.hbs | 4 +- .../components/list-table/table-body.hbs | 2 +- .../components/multi-select-dropdown.hbs | 14 +- ui/app/templates/components/page-layout.hbs | 6 +- .../templates/components/page-size-select.hbs | 8 +- .../components/placement-failure.hbs | 6 +- .../components/plugin-allocation-row.hbs | 54 +++---- ui/app/templates/components/popover-menu.hbs | 12 +- .../templates/components/primary-metric.hbs | 22 +-- .../templates/components/region-switcher.hbs | 10 +- .../components/reschedule-event-row.hbs | 26 +-- .../components/reschedule-event-timeline.hbs | 20 +-- ui/app/templates/components/search-box.hbs | 6 +- .../templates/components/server-agent-row.hbs | 12 +- ui/app/templates/components/server-subnav.hbs | 4 +- ui/app/templates/components/stepper-input.hbs | 16 +- .../templates/components/streaming-file.hbs | 2 +- .../templates/components/task-group-row.hbs | 26 +-- ui/app/templates/components/task-log.hbs | 12 +- ui/app/templates/components/task-row.hbs | 46 +++--- ui/app/templates/components/task-subnav.hbs | 6 +- ui/app/templates/components/toggle.hbs | 6 +- .../templates/components/two-step-button.hbs | 28 ++-- ui/app/templates/csi/plugins/index.hbs | 30 ++-- .../csi/plugins/plugin/allocations.hbs | 40 ++--- ui/app/templates/csi/plugins/plugin/index.hbs | 66 ++++---- ui/app/templates/csi/volumes/index.hbs | 30 ++-- ui/app/templates/csi/volumes/volume.hbs | 30 ++-- ui/app/templates/exec.hbs | 24 +-- ui/app/templates/head.hbs | 2 +- ui/app/templates/jobs/index.hbs | 60 +++---- ui/app/templates/jobs/job/allocations.hbs | 26 +-- ui/app/templates/jobs/job/definition.hbs | 16 +- ui/app/templates/jobs/job/deployments.hbs | 6 +- ui/app/templates/jobs/job/evaluations.hbs | 12 +- ui/app/templates/jobs/job/index.hbs | 12 +- ui/app/templates/jobs/job/loading.hbs | 2 +- ui/app/templates/jobs/job/task-group.hbs | 68 ++++---- ui/app/templates/jobs/job/versions.hbs | 6 +- ui/app/templates/jobs/run.hbs | 4 +- ui/app/templates/servers/index.hbs | 14 +- ui/app/templates/servers/server/index.hbs | 16 +- ui/app/templates/servers/server/monitor.hbs | 10 +- ui/app/templates/settings/tokens.hbs | 22 +-- 118 files changed, 1135 insertions(+), 1134 deletions(-) diff --git a/ui/.template-lintrc.js b/ui/.template-lintrc.js index a0c20fdc2..fea180ebf 100644 --- a/ui/.template-lintrc.js +++ b/ui/.template-lintrc.js @@ -34,5 +34,6 @@ module.exports = { // remove when moving from extending `recommended` to `octane` 'no-curly-component-invocation': true, + 'no-implicit-this': true, }, }; diff --git a/ui/app/templates/allocations/allocation/fs.hbs b/ui/app/templates/allocations/allocation/fs.hbs index 568087ca4..d1c29f2a5 100644 --- a/ui/app/templates/allocations/allocation/fs.hbs +++ b/ui/app/templates/allocations/allocation/fs.hbs @@ -1,10 +1,10 @@ -{{title pathWithLeadingSlash " - Allocation " allocation.shortId " filesystem"}} - +{{title this.pathWithLeadingSlash " - Allocation " this.allocation.shortId " filesystem"}} + \ No newline at end of file + @model={{this.allocation}} + @path={{this.path}} + @stat={{this.stat}} + @isFile={{this.isFile}} + @directoryEntries={{this.directoryEntries}} + @sortProperty={{this.sortProperty}} + @sortDescending={{this.sortDescending}} /> \ No newline at end of file diff --git a/ui/app/templates/allocations/allocation/index.hbs b/ui/app/templates/allocations/allocation/index.hbs index 8db6717c9..11b9df8a9 100644 --- a/ui/app/templates/allocations/allocation/index.hbs +++ b/ui/app/templates/allocations/allocation/index.hbs @@ -1,15 +1,15 @@ -{{title "Allocation " model.name}} - +{{title "Allocation " this.model.name}} +
- {{#if error}} + {{#if this.error}}
-

{{error.title}}

-

{{error.description}}

+

{{this.error.title}}

+

{{this.error.description}}

- +
@@ -17,13 +17,13 @@

- Allocation {{model.name}} - {{model.clientStatus}} + Allocation {{this.model.name}} + {{this.model.clientStatus}}
- {{#if model.isRunning}} + {{#if this.model.isRunning}}
- +
+ @awaitingConfirmation={{this.stopAllocation.isRunning}} + @disabled={{or this.stopAllocation.isRunning this.restartAllocation.isRunning}} + @onConfirm={{perform this.stopAllocation}} /> + @awaitingConfirmation={{this.restartAllocation.isRunning}} + @disabled={{or this.stopAllocation.isRunning this.restartAllocation.isRunning}} + @onConfirm={{perform this.restartAllocation}} /> {{/if}}

- {{model.id}} - + {{this.model.id}} +
Allocation Details Job - {{model.job.name}} + {{this.model.job.name}} Client - {{model.node.shortId}} + {{this.model.node.shortId}}
@@ -71,13 +71,13 @@ Resource Utilization
- {{#if model.isRunning}} + {{#if this.model.isRunning}}
- +
- +
{{else}} @@ -89,18 +89,18 @@
- +
Tasks
-
- {{#if sortedStates.length}} +
+ {{#if this.sortedStates.length}} @@ -129,13 +129,13 @@
- {{#if network.ports.length}} + {{#if this.network.ports.length}}
Ports
- + Name Dynamic? @@ -147,7 +147,7 @@ {{row.model.name}} {{if row.model.isDynamic "Yes" "No"}} - {{network.ip}}:{{row.model.port}} + {{this.network.ip}}:{{row.model.port}} {{row.model.to}} @@ -157,13 +157,13 @@
{{/if}} - {{#if services.length}} + {{#if this.services.length}}
Services
- + Name Port @@ -189,47 +189,47 @@
{{/if}} - {{#if model.hasRescheduleEvents}} + {{#if this.model.hasRescheduleEvents}}
Reschedule Events
- +
{{/if}} - {{#if model.wasPreempted}} + {{#if this.model.wasPreempted}}
Preempted By
- {{#if preempter}} + {{#if this.preempter}}
- - {{preempter.clientStatus}} + + {{this.preempter.clientStatus}} - {{preempter.name}} - {{preempter.shortId}} + {{this.preempter.name}} + {{this.preempter.shortId}} Job - {{preempter.job.name}} + {{this.preempter.job.name}} Priority - {{preempter.job.priority}} + {{this.preempter.job.priority}} Client - {{preempter.node.shortId}} + {{this.preempter.node.shortId}} Reserved CPU - {{preempter.resources.cpu}} MHz + {{this.preempter.resources.cpu}} MHz Reserved Memory - {{preempter.resources.memory}} MiB + {{this.preempter.resources.memory}} MiB
@@ -243,12 +243,12 @@
{{/if}} - {{#if (and model.preemptedAllocations.isFulfilled model.preemptedAllocations.length)}} + {{#if (and this.model.preemptedAllocations.isFulfilled this.model.preemptedAllocations.length)}}
Preempted Allocations
diff --git a/ui/app/templates/allocations/allocation/task/fs.hbs b/ui/app/templates/allocations/allocation/task/fs.hbs index 1c8d66dca..945cfa475 100644 --- a/ui/app/templates/allocations/allocation/task/fs.hbs +++ b/ui/app/templates/allocations/allocation/task/fs.hbs @@ -1,10 +1,10 @@ -{{title pathWithLeadingSlash " - Task " taskState.name " filesystem"}} - +{{title this.pathWithLeadingSlash " - Task " this.taskState.name " filesystem"}} + \ No newline at end of file + @model={{this.taskState}} + @path={{this.path}} + @stat={{this.stat}} + @isFile={{this.isFile}} + @directoryEntries={{this.directoryEntries}} + @sortProperty={{this.sortProperty}} + @sortDescending={{this.sortDescending}} /> \ No newline at end of file diff --git a/ui/app/templates/allocations/allocation/task/index.hbs b/ui/app/templates/allocations/allocation/task/index.hbs index 127874104..f274e1312 100644 --- a/ui/app/templates/allocations/allocation/task/index.hbs +++ b/ui/app/templates/allocations/allocation/task/index.hbs @@ -1,15 +1,15 @@ -{{title "Task " model.name}} - +{{title "Task " this.model.name}} +
- {{#if error}} + {{#if this.error}}
-

{{error.title}}

-

{{error.description}}

+

{{this.error.title}}

+

{{this.error.description}}

- +
@@ -17,20 +17,20 @@

- {{model.name}} - {{#if model.isConnectProxy}} + {{this.model.name}} + {{#if this.model.isConnectProxy}} {{/if}} - {{model.state}} + {{this.model.state}}
- {{#if model.isRunning}} + {{#if this.model.isRunning}}
+ @job={{this.model.task.taskGroup.job}} + @taskGroup={{this.model.task.taskGroup}} + @allocation={{this.model.allocation}} + @task={{this.model.task}} />
+ @awaitingConfirmation={{this.restartTask.isRunning}} + @disabled={{this.restartTask.isRunning}} + @onConfirm={{perform this.restartTask}} /> {{/if}}

@@ -51,21 +51,21 @@ Task Details Started At - {{format-ts model.startedAt}} + {{format-ts this.model.startedAt}} - {{#if model.finishedAt}} + {{#if this.model.finishedAt}} Finished At - {{format-ts model.finishedAt}} + {{format-ts this.model.finishedAt}} {{/if}} Driver - {{model.task.driver}} + {{this.model.task.driver}} Lifecycle - {{model.task.lifecycleName}} + {{this.model.task.lifecycleName}}
@@ -75,13 +75,13 @@ Resource Utilization
- {{#if model.isRunning}} + {{#if this.model.isRunning}}
- +
- +
{{else}} @@ -93,13 +93,13 @@
- {{#if (and (not model.task.lifecycle) prestartTaskStates)}} + {{#if (and (not this.model.task.lifecycle) this.prestartTaskStates)}}
Prestart Tasks
- + Task @@ -125,13 +125,13 @@
{{/if}} - {{#if network.ports.length}} + {{#if this.network.ports.length}}
Addresses
- + Dynamic? Name @@ -142,8 +142,8 @@ {{if row.model.isDynamic "Yes" "No"}} {{row.model.name}} - - {{network.ip}}:{{row.model.port}} + + {{this.network.ip}}:{{row.model.port}} @@ -153,13 +153,13 @@
{{/if}} - {{#if model.task.volumeMounts.length}} + {{#if this.model.task.volumeMounts.length}}
Volumes
- + Name Destination @@ -192,7 +192,7 @@ Recent Events
- + Time Type diff --git a/ui/app/templates/allocations/allocation/task/logs.hbs b/ui/app/templates/allocations/allocation/task/logs.hbs index 69132b20c..0cd039a05 100644 --- a/ui/app/templates/allocations/allocation/task/logs.hbs +++ b/ui/app/templates/allocations/allocation/task/logs.hbs @@ -1,5 +1,5 @@ -{{title "Task " model.name " logs"}} - +{{title "Task " this.model.name " logs"}} +
- +
diff --git a/ui/app/templates/application.hbs b/ui/app/templates/application.hbs index c2ed3ae81..d2ed5fd6b 100644 --- a/ui/app/templates/application.hbs +++ b/ui/app/templates/application.hbs @@ -1,25 +1,25 @@ -{{title (if system.shouldShowRegions (concat system.activeRegion " - ")) "Nomad" separator=" - "}} +{{title (if this.system.shouldShowRegions (concat this.system.activeRegion " - ")) "Nomad" separator=" - "}} -{{#unless error}} +{{#unless this.error}} {{outlet}} {{else}}
- {{#if isNoLeader}} + {{#if this.isNoLeader}}

No Cluster Leader

The cluster has no leader. Read about Outage Recovery.

- {{else if is500}} + {{else if this.is500}}

Server Error

A server error prevented data from being sent to the client.

- {{else if is404}} + {{else if this.is404}}

Not Found

What you're looking for couldn't be found. It either doesn't exist or you are not authorized to see it.

- {{else if is403}} + {{else if this.is403}}

Not Authorized

- {{#if token.secret}} + {{#if this.token.secret}}

Your ACL token does not provide the required permissions. Contact your administrator if this is an error.

{{else}}

Provide an ACL token with requisite permissions to view this.

@@ -28,8 +28,8 @@

Error

Something went wrong.

{{/if}} - {{#if (eq config.environment "development")}} -
{{errorStr}}
+ {{#if (eq this.config.environment "development")}} +
{{this.errorStr}}
{{/if}}