This repository has been archived by the owner on Nov 22, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- created an enum for a property definition control type
- moved the getControlType() function from the property definition model into the PropertyControlType enum - changed html switch to use the enum
- Loading branch information
1 parent
98580ea
commit 6aaca0a
Showing
5 changed files
with
83 additions
and
23 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
ngapp/src/app/shared/property-form/property-control-type.enum.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/** | ||
* @license | ||
* Copyright 2017 JBoss Inc | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { PropertyDefinition } from "@shared/property-form/property-definition.model"; | ||
|
||
/** | ||
* An enumeration of control types for a property. | ||
*/ | ||
|
||
export enum PropertyControlType { | ||
|
||
/** | ||
* Render the property as a checkbox. | ||
*/ | ||
CHECKBOX, | ||
|
||
/** | ||
* Render the property as a dropdown. | ||
*/ | ||
DROPDOWN, | ||
|
||
/** | ||
* Render the property as a masked textbox. | ||
*/ | ||
PASSWORD, | ||
|
||
/** | ||
* Render the property as a textbox. | ||
*/ | ||
TEXT | ||
|
||
} | ||
|
||
/** | ||
* Namespace to allow methods on the enum. | ||
*/ | ||
export namespace PropertyControlType { | ||
|
||
/** | ||
* @param {PropertyDefinition<any>} propDefn the property whose control type is being requested | ||
* @returns {PropertyControlType} the control type to render the property value | ||
*/ | ||
export function toControlType( propDefn: PropertyDefinition< any > ): PropertyControlType { | ||
if ( propDefn.isConstrainedToAllowedValues() ) { | ||
return PropertyControlType.DROPDOWN; | ||
} | ||
|
||
if ( propDefn.getTypeClassName() === "java.lang.Boolean" ) { | ||
return PropertyControlType.CHECKBOX; | ||
} | ||
|
||
if ( propDefn.isMasked() || propDefn.getId() === "password" ) { | ||
return PropertyControlType.PASSWORD; | ||
} | ||
|
||
// defaults to a text control | ||
return PropertyControlType.TEXT; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 5 additions & 5 deletions
10
...src/app/shared/property-form/property-form-property/property-form-property.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters