Skip to content

Commit

Permalink
Update tool deployment field name
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljcollinsuk committed Jan 3, 2025
1 parent 4f7ddd7 commit 9f42031
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion controlpanel/api/views/tool_deployments.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def _deploy(self):
)

def post(self, request, *args, **kwargs):
self.serializer = self.get_serializer(data={"tool": request.data.get("version")})
self.serializer = self.get_serializer(data=request.data)
self.serializer.is_valid(raise_exception=True)

tool_action = self.kwargs["action"]
Expand Down
8 changes: 4 additions & 4 deletions controlpanel/frontend/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ def create_option(self, name, value, label, selected, index, subindex=None, attr

class ToolForm(forms.Form):

version = forms.ModelChoiceField(
tool = forms.ModelChoiceField(
queryset=Tool.objects.none(),
empty_label=None,
widget=ToolChoice(attrs={"class": "govuk-select govuk-!-width-full govuk-!-font-size-16"}),
Expand All @@ -693,12 +693,12 @@ def __init__(self, *args, **kwargs):
self.tool_type = kwargs.pop("tool_type")
self.deployment = kwargs.pop("deployment", None)
super().__init__(*args, **kwargs)
self.fields["version"].queryset = self.get_tool_release_choices(tool_type=self.tool_type)
self.fields["version"].widget.attrs.update(
self.fields["tool"].queryset = self.get_tool_release_choices(tool_type=self.tool_type)
self.fields["tool"].widget.attrs.update(
{"data-action-target": self.tool_type, "id": f"tools-{self.tool_type}"}
)
if self.deployment:
self.fields["version"].initial = self.deployment.tool
self.fields["tool"].initial = self.deployment.tool

def get_tool_release_choices(self, tool_type: str):
return Tool.objects.filter(
Expand Down
4 changes: 2 additions & 2 deletions controlpanel/frontend/jinja2/tool-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ <h2 class="govuk-heading-m">{{ tool_form.tool_type }}</h2>
method="post">
{{ csrf_input }}
<div class="govuk-form-group">
<label class="govuk-label" for="version">
<label class="govuk-label" for="tool">
Version
</label>
{{ tool_form.version }}
{{ tool_form.tool }}
</div>
</form>
</div>
Expand Down
12 changes: 6 additions & 6 deletions controlpanel/frontend/static/javascripts/modules/tool-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ moj.Modules.toolStatus = {
listenerClass: ".tool",
statusLabelClass: ".tool-status-label",

versionSelector: "select[name='version']",
versionSelector: "select[name='tool']",
versionNotInstalledClass: "not-installed",
versionInstalledClass: "installed",
installedSuffix: " (installed)",
Expand All @@ -19,7 +19,7 @@ moj.Modules.toolStatus = {
this.bindEvents(toolStatusListeners);
}

// Bind version selects' change event listeners
// Bind tool selects' change event listeners
const versionSelects = document.querySelectorAll(this.versionSelector);
versionSelects.forEach(versionSelect => {
versionSelect.addEventListener("change", (event) => this.versionSelectChanged(event.target));
Expand Down Expand Up @@ -68,7 +68,7 @@ moj.Modules.toolStatus = {
};
},

// Select the new version from the tool "version" select input
// Select the new tool from the tool select input
updateAppVersion(listener, newVersionData) {
const selectElement = listener.querySelector(this.versionSelector);

Expand All @@ -80,15 +80,15 @@ moj.Modules.toolStatus = {
notInstalledOption.remove();
}

// 2. remove "(installed)" suffix and class from old version
// 2. remove "(installed)" suffix and class from old tool version
let oldVersionOption = selectElement.querySelector("option." + this.versionInstalledClass);

if (oldVersionOption) {
oldVersionOption.label = oldVersionOption.label.replace(this.installedSuffix, "");
oldVersionOption.classList.remove(this.versionInstalledClass);
}

// 3. add "(installed)" suffix and class to new version
// 3. add "(installed)" suffix and class to new tool version
let newVersionOption = listener.querySelector(this.versionSelector + " option[value='" + newVersionData.tool_id + "']");
if (newVersionOption) {
newVersionOption.label = newVersionOption.label + this.installedSuffix;
Expand Down Expand Up @@ -141,7 +141,7 @@ moj.Modules.toolStatus = {
});
},

// version select "change" event handler
// tool version select "change" event handler
versionSelectChanged(target) {
const selected = target.options[target.options.selectedIndex];
const classes = selected.className.split(" ");
Expand Down

0 comments on commit 9f42031

Please sign in to comment.