Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compare new and old boolean field development #981

Open
wants to merge 3 commits into
base: feature/boolean-field-2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions app/config/field-type-service.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,19 @@
"hasInstanceTerm": false,
"allowsRequired": true
},
{
"cedarType": "boolean",
"iconClass": "fa fa-check-circle",
"allowedInElement": true,
"primaryField": true,
"Label": "Boolean",
"hasControlledTerms": false,
"staticField": false,
"allowsMultiple": true,
"allowsValueRecommendation": false,
"hasInstanceTerm": false,
"allowsRequired": true
},
{
"cedarType": "phone-number",
"iconClass": "fa fa-th",
Expand Down
10 changes: 8 additions & 2 deletions app/resources/i18n/locale-en.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@
"numeric": {
"NAME": "Numeric"
},
"boolean": {
"NAME": "Boolean",
"Labels": "Labels",
"SelectDefaultLabel": "Select default value",
"True": "True",
"False": "False",
"Null": "Not set"
},
"phone-number": {
"NAME": "Phone"
},
Expand Down Expand Up @@ -85,7 +93,6 @@
"MoreTemplates": "More Templates",
"Save": "Save",
"Validate": "Validate",
"Next": "Next",
"Previous": "Previous",
"Name": "Name",
"Identifier": "Identifier",
Expand Down Expand Up @@ -124,7 +131,6 @@
"Elements": "Elements",
"FilterBy": "Filter by",
"Untitled": "Untitled",
"Description": "Description",
"SelectToViewDetails": "Select a resource to view its details",
"canRead": "can read",
"canWrite": "can write",
Expand Down
72 changes: 72 additions & 0 deletions app/scripts/form/field-create/boolean.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<div id="numeric-{{field['@id'].substring(field['@id'].lastIndexOf('/')+1)}}" class="input-type-container">

<div ng-include="'scripts/form/partials/field-header.partial.html'"></div>
<div class="definition-inputs" ng-include="'scripts/form/partials/field-definition.partial.html'"></div>

<!-- radio items -->
<div class="form-group floating-label-wrapper">
<div class="options-wrapper">
<div ng-init="initializeSelectionField()" class="multiple-container">
<div class="">{{'FIELDS.FIELD_TYPE.boolean.Labels' | translate}}</div>
<table style="border-spacing: 3px; border-collapse: separate; border:0px">
<tr>
<td>{{'FIELDS.FIELD_TYPE.boolean.True' | translate}}:</td>
<td>
<div class="form-group floating-label-wrapper">
<input type="text" class="form-control"
id="label-true-{{field['@id'].substring(field['@id'].lastIndexOf('/')+1)}}" placeholder="{{'FIELDS.FIELD_TYPE.boolean.True' | translate}}"
aria-label="Boolean" ng-model="getLabels()['true']" with-floating-label>
</div>
</td>
</tr>
<tr>
<td>{{'FIELDS.FIELD_TYPE.boolean.False' | translate}}:</td>
<td>
<div class="form-group floating-label-wrapper">
<input type="text" class="form-control"
id="label-false-{{field['@id'].substring(field['@id'].lastIndexOf('/')+1)}}" placeholder="{{'FIELDS.FIELD_TYPE.boolean.False' | translate}}"
aria-label="Boolean" ng-model="getLabels()['false']" with-floating-label>
</div>
</td>
</tr>
<tr>
<td>{{'FIELDS.FIELD_TYPE.boolean.Null' | translate}}:</td>
<td>
<div class="form-group floating-label-wrapper">
<input type="text" class="form-control"
id="label-null-{{field['@id'].substring(field['@id'].lastIndexOf('/')+1)}}" placeholder="{{'FIELDS.FIELD_TYPE.boolean.Null' | translate}}"
aria-label="Boolean" ng-model="getLabels()['null']" with-floating-label>
</div>
</td>
</tr>
</table>
</div>
<p class="instructions">{{'FIELDS.FIELD_TYPE.boolean.SelectDefaultLabel' | translate}}:</p>
<!-- <p class="instructions">-->
<!-- <select ng-model="getValueConstraints()['defaultValue']" class="col-sm-4 select-picker group-permission">-->
<!-- <option value="true" translate>FIELDS.FIELD_TYPE.boolean.True</option>-->
<!-- <option value="false" translate>FIELDS.FIELD_TYPE.boolean.False</option>-->
<!-- <option value="null" translate>FIELDS.FIELD_TYPE.boolean.Null</option>-->
<!-- </select>-->
<!-- </p>-->

<ui-select
class="form-control"
theme="bootstrap"
close-on-select="true"
ng-model="getValueConstraints()['defaultValue']"
ng-disabled="false">
<ui-select-match placeholder="{{'CREATOR.enterNumberType' | translate}}">{{selectedNumberType.label}}
</ui-select-match>
<ui-select-choices repeat="option in getBooleanFieldDefaultValueOptions()">
{{option.label}}
</ui-select-choices>
</ui-select>

</div>
</div>


<div class="configuration-options " ng-include="'scripts/form/partials/configuration-options.partial.html'"></div>

</div>
9 changes: 9 additions & 0 deletions app/scripts/form/field-render/boolean.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<div class="fields fields-numeric">

<!-- header -->
<div ng-init="fieldTitle='Number';fieldIconClass='cedar-svg-number'" ng-include="'scripts/form/partials/field-header.partial.html'"></div>
<!-- title and description -->
<div class="definition-inputs"
ng-include="'scripts/form/partials/field-definition.partial.html'"></div>

</div>
11 changes: 11 additions & 0 deletions app/scripts/form/field.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ define([
return schemaService.getValueConstraints($scope.field);
};

$scope.getBooleanFieldDefaultValueOptions = function () {
return [
{id: '12h', label: "Use AM/PM Input"},
{id: '24h', label: "Use 24H Input"}
];
};

// has value constraints?
$scope.isConstrained = function () {
return schemaService.isConstrained($scope.field);
Expand Down Expand Up @@ -294,6 +301,10 @@ define([
return schemaService.getLiterals($scope.field);
};

$scope.getLabels = function () {
return schemaService.getLabels($scope.field);
};

// default the cardinality to 1..N
$scope.defaultMinMax = function () {
schemaService.defaultMinMax($scope.field);
Expand Down
10 changes: 10 additions & 0 deletions app/scripts/service/schema.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,16 @@ define([
if (node && service.hasValueConstraints(node)) return service.getValueConstraints(node).literals;
};

// get the value constraint labels values
service.getLabels = function (node) {
if (node && service.hasValueConstraints(node)) return service.getValueConstraints(node).labels;
};

// get the default value
service.getDefaultValue = function (node) {
if (node && service.hasValueConstraints(node)) return service.getValueConstraints(node).defaultValue;
};

// is this a required field or element?
service.isRequired = function (node) {
if (node && service.getValueConstraints(node)) return service.getValueConstraints(node).requiredValue;
Expand Down
19 changes: 13 additions & 6 deletions app/scripts/service/staging.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ define([

StagingService.$inject = ["$rootScope", "$document", "TemplateElementService", "TemplateFieldService",
"DataManipulationService",'schemaService',
"UIUtilService",
"UIUtilService", "$translate",
"ClientSideValidationService", "UIMessageService", "FieldTypeService", "$timeout",
"AuthorizedBackendService", "DataTemplateService",
"CONST"];

function StagingService($rootScope, $document, TemplateElementService, TemplateFieldService,
DataManipulationService,schemaService, UIUtilService,
DataManipulationService,schemaService, UIUtilService, $translate,
ClientSideValidationService, UIMessageService, FieldTypeService, $timeout,
AuthorizedBackendService, DataTemplateService, CONST) {

Expand Down Expand Up @@ -119,13 +119,12 @@ define([
// };

service.addFieldToForm = function (form, fieldType, firstClassField, divId, callback) {

var field = DataManipulationService.generateField(fieldType, firstClassField);
let field = DataManipulationService.generateField(fieldType, firstClassField);
UIUtilService.setSelected(field);

// is it a checkbox, list, or radio field?
if (schemaService.isCheckboxListRadioType(fieldType)) {
if (fieldType == 'checkbox') { // multiple choice field (checkbox)
if (fieldType === 'checkbox') { // multiple choice field (checkbox)
field.items._valueConstraints.multipleChoice = true;
field.items._valueConstraints.literals = [
{
Expand All @@ -141,10 +140,18 @@ define([
}
];
}
} else if (fieldType === 'boolean') {
field._valueConstraints.multipleChoice = false;
field._valueConstraints.labels = {
'true': $translate.instant('FIELDS.FIELD_TYPE.boolean.True'),
'false': $translate.instant('FIELDS.FIELD_TYPE.boolean.False'),
'null': $translate.instant('FIELDS.FIELD_TYPE.boolean.Null')
};
field._valueConstraints.defaultValue = 'false';
}

// Converting title for irregular character handling
var fieldName = DataManipulationService.generateGUID(); //field['@id'];
let fieldName = DataManipulationService.generateGUID(); //field['@id'];

// Adding corresponding property type to @context (only if the field is not static)
if (!FieldTypeService.isStaticField(fieldType)) {
Expand Down