Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
WIP: Add api service to post variables back to server
Browse files Browse the repository at this point in the history
  • Loading branch information
gregone committed Aug 9, 2021
1 parent aac5a6b commit e452342
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 5 deletions.
13 changes: 12 additions & 1 deletion ui/app/components/project-config-variables/list-item.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';
import { ConfigVar, Project } from 'waypoint-pb';
import { ConfigSetRequest, ConfigVar, Project, SetConfigSourceRequest } from 'waypoint-pb';
import { inject as service } from '@ember/service';
import ApiService from 'waypoint/services/api';

interface VariableArgs {
variable: ConfigVar.AsObject;
Expand All @@ -15,6 +17,9 @@ interface VariableArgs {
}

export default class ProjectConfigVariablesListItemComponent extends Component<VariableArgs> {
@service api!: ApiService;
@service flashMessages;

initialVariable: ConfigVar.AsObject;
@tracked variable: ConfigVar.AsObject;
@tracked isCreating: boolean;
Expand Down Expand Up @@ -47,6 +52,12 @@ export default class ProjectConfigVariablesListItemComponent extends Component<V
@action
async saveVariable(e) {
e.preventDefault();
if (this.variable.name === '' || this.variable.pb_static === '') {
return this.flashMessages.error('Variable keys or values can not be empty');
}
let req = new ConfigSetRequest();
let savedVars = await this.args.saveVariableSettings(this.variable, this.initialVariable);
debugger;
// todo
}

Expand Down
28 changes: 26 additions & 2 deletions ui/app/components/project-config-variables/list.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';
import { ConfigVar } from 'waypoint-pb';
import { ConfigSetRequest, ConfigVar, Project } from 'waypoint-pb';
import { inject as service } from '@ember/service';
import ApiService from 'waypoint/services/api';

interface ProjectConfigArgs {
variablesList: ConfigVar.AsObject[];
project: Project.AsObject;
}

export default class ProjectConfigVariablesListComponent extends Component<ProjectConfigArgs> {
@service api!: ApiService;

@tracked variablesList: Array<ConfigVar.AsObject>;
@tracked project: Project.AsObject;
@tracked isCreating: boolean;
@tracked activeVariable;

constructor(owner: any, args: any) {
super(owner, args);
let { variablesList } = args;
let { variablesList, project } = args;
this.variablesList = variablesList;
this.project = project;
this.activeVariable = null;
this.isCreating = false;
}
Expand All @@ -29,4 +36,21 @@ export default class ProjectConfigVariablesListComponent extends Component<Proje
this.activeVariable = newVarObj;
}

@action
async saveVariableSettings(
variable?: ConfigVar.AsObject,
initialVariable?: ConfigVar.AsObject
): Promise<any | void> {
let project = this.project;
let projectRef = new Project();
projectRef.setName(project.name);

let req = new ConfigSetRequest();
// TODO: Maintain variablesList in proto form and update as needed.
// let protoVariablesList = this.variablesList.map(v=> {
// return new ConfigVar();
// });

// req.setVariablesList()
}
}
3 changes: 2 additions & 1 deletion ui/app/components/project-input-variables/list-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ interface VariableArgs {
}

export default class ProjectInputVariablesListItemComponent extends Component<VariableArgs> {
initialVariable: Variable.AsObject;
@service api!: ApiService;
@service flashMessages;

initialVariable: Variable.AsObject;
@tracked variable: Variable.AsObject;
@tracked isCreating: boolean;
@tracked isEditing: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,11 @@ export default class WorkspaceProjectsProjectSettingsConfigVariables extends Rou
let config = await this.api.client.getConfig(req, this.api.WithMeta());
return config?.toObject();
}

setupController(controller, model, transition) {
super.setupController(controller, model, transition);
let project = this.modelFor('workspace.projects.project');

controller.project = project;
}
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<ProjectConfigVariables::List @variablesList={{this.model.variablesList}}/>
<ProjectConfigVariables::List @variablesList={{this.model.variablesList}} @project={{this.project}}/>
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,10 @@ module('Integration | Component | project-config-variables-list', function (hook
this.set('variablesList', varList);
await render(hbs`<ProjectConfigVariables::List @variablesList={{this.variablesList}}/>`);
assert.dom('.variables-list').exists('The list renders');
assert.equal(page.variablesList.length, 10, 'it renders: the list has the proper length');
});

// test('only static variables are editable', async function (assert) {});
// test('internal variables', async function (assert) {});
// test('nameIsPath', async function (assert) {});
});

0 comments on commit e452342

Please sign in to comment.