Skip to content

Commit

Permalink
edit variable and add variable working
Browse files Browse the repository at this point in the history
  • Loading branch information
mikemitchel committed Aug 27, 2024
1 parent 0aaf80d commit a69a2aa
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/pages-tab/components/page-fields/page-fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const FieldVM = DefineMap.extend('FieldVM', {
return pageFieldsHelpers.getExpectedVarType(this.type)
},

hasValidType: {
hasValidTypes: {
value ({ listenTo, resolve }) {
let fieldType = this.type && this.type.toLowerCase()
let varType = this.varType && this.varType.toLowerCase()
Expand Down
2 changes: 1 addition & 1 deletion src/pages-tab/components/page-fields/page-fields.stache
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
</select>
</div>
</div>
{{#not(fieldVM.hasValidType)}}
{{#not(fieldVM.hasValidTypes)}}
<health-message message:from="fieldVM.problemMessage"></health-message>
{{/not}}
<var-picker-field appState:from="appState" filterText:bind="fieldVM.name" obj:bind="fieldVM.field" key:from="'name'" />
Expand Down
17 changes: 16 additions & 1 deletion src/pages-tab/components/var-picker/field/var-picker-field.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@ export const VarPickerField = DefineMap.extend('VarPickerField', {
default: ''
},

get assignedVariable () {
const validVarName = this.validVarName(this.filterText)
const partialVariable = new TVariable()
Object.assign(partialVariable, { name: this.filterText, type: 'Text' })
const assignedVariable = validVarName ? this.appState.guide.vars[this.filterText.toLowerCase()] : partialVariable

console.log('assignedVariable', assignedVariable)
return assignedVariable
},

get blankVariable () {
return new TVariable()
},

newObservableBool (tf = false) {
return new DefineMap({ value: tf })
},
Expand Down Expand Up @@ -66,6 +80,7 @@ export const VarPickerField = DefineMap.extend('VarPickerField', {
newVarData: {},

onVariableChange (variable) {
console.log('onvarchange', variable)
this.newVarData = variable
},

Expand All @@ -76,7 +91,7 @@ export const VarPickerField = DefineMap.extend('VarPickerField', {
}
},

addVarCB (bool) {
addEditVarCB (bool) {
return () => {
const variable = this.newVarData
const name = variable && variable.name
Expand Down
32 changes: 29 additions & 3 deletions src/pages-tab/components/var-picker/field/var-picker-field.stache
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<div class="divvariable auto-close-shared-bool-on-outside-focus">
{{let nameVarPickerVisible = newObservableBool(false)}}
{{let showVariableModal = newObservableBool(false)}}
{{let showVariableEditModal = newObservableBool(false)}}
<label class="control-label">{{label}}</label>
<div class="form-group has-var-picker">
<input
Expand All @@ -28,6 +29,11 @@
<var-picker appState:from="appState" varName:bind="filterText" selectedCallback:from="nameVarPickerVisible.value = false" />
{{/if}}
</div>
<div class="var-picker-edit">
<button class="newvar-button btn btn-default btn-wide-sm" on:click="makeTrueAndFocusPopup(showVariableEditModal)" style="margin-top: 4px;">
<span class="glyphicon-plus" aria-hidden="true"></span> Edit Current
</button>
</div>
<div class="var-picker-add">
<button class="newvar-button btn btn-default btn-wide-sm" on:click="makeTrueAndFocusPopup(showVariableModal)" style="margin-top: 4px;">
<span class="glyphicon-plus" aria-hidden="true"></span> Add New
Expand All @@ -37,13 +43,33 @@

{{#if(showVariableModal.value)}}
<author-modal
modalTitle:raw="Add New Variable"
modalTitle:raw="Add Variable"
cancelText:raw="Cancel"
submitText:raw="Save"
onCancel:from="makeFalseAndClearDataCB(showVariableModal)"
onSubmit:from="addVarCB(showVariableModal)"
onSubmit:from="addEditVarCB(showVariableModal)"
>
<variable-editor showUsageFinder:from="{{false}}" onVariableChange:from="onVariableChange" />
<variable-editor
initialVariable:from="blankVariable"
showUsageFinder:from="{{false}}"
onVariableChange:from="onVariableChange"
/>
</author-modal>
{{/if}}

{{#if(showVariableEditModal.value)}}
<author-modal
modalTitle:raw="Edit Variable"
cancelText:raw="Cancel"
submitText:raw="Save"
onCancel:from="makeFalseAndClearDataCB(showVariableEditModal)"
onSubmit:from="addEditVarCB(showVariableEditModal)"
>
<variable-editor
initialVariable:from="assignedVariable"
showUsageFinder:raw="true"
onVariableChange:from="onVariableChange"
/>
</author-modal>
{{/if}}
</div>

0 comments on commit a69a2aa

Please sign in to comment.