Example #1
0
  /**
   *
   * This method sets default value for a dialog field
   * @memberof DialogDataService
   * @function setDefaultValue
   * @param data {any} This is a object that is all the information for a particular dialog field
   *
   **/
  private setDefaultValue(data): any {
    let defaultValue: any = '';
    const firstOption = 0; // these are meant to help make code more readable
    const fieldValue = 0;

    if (_.isObject(data.values)) {
      defaultValue = data.values[firstOption][fieldValue];
    }

    if (data.type === 'DialogFieldDateControl' || data.type === 'DialogFieldDateTimeControl') {
      defaultValue = data.values ? new Date(data.values) : new Date();
    }

    if (data.default_value) {
      defaultValue = data.default_value;
    }

    if (data.type === 'DialogFieldDropDownList' && data.options.force_multi_value && data.default_value) {
      defaultValue = JSON.parse(data.default_value);
    }

    if (data.type === 'DialogFieldTagControl') {
      // setting the default_value for a tag control's select box
      // In case the default_value is not set for the ng-model of the component, an empty value option is displayed
      let defaultOption = _.find(data.values, { id: null });
      if (defaultOption) {
        defaultOption.id = 0;
        defaultValue = defaultOption.id;
      }
    }

    if (this.checkboxNeedsNewDefaultValue(data)) {
      defaultValue = data.values;
    }

    return defaultValue;
  }
function retrieveFileFromDb (file) {
	
	assert (_.isObject (file), 'file not an object');
	
	return new Promise (function (resolve, reject) {
	
		// Create a file with a name of the form 'file._id.<ext>', where <ext> is the extension of the original file
		var filepath = __dirname + '/../client-build/' + file._id + '.' + file.filename.substr(file.filename.lastIndexOf('.')+1);

		// Check whether the file already exists
		fs.open (filepath, 'r', function (err, fd) {
			if (!err) {
				// File already exits
				fs.closeSync (fd);
				resolve (null);
			}
			else {
				// File does not exist...create it
				var fs_write_stream = fs.createWriteStream (filepath);

				var gfs = Grid(conn.db);

				//read from mongodb
				var readstream = gfs.createReadStream ({_id: file._id});
				readstream.pipe (fs_write_stream);
				fs_write_stream.on ('close', function () {
					console.log ('file created: ' + filepath);
					resolve (null);
				});
				fs_write_stream.on ('error', function () {
					err = 'file creation error: ' + filepath;
					reject (err);
				});
			}
		});
	});
}
Example #3
0
export function collectFrozenNodes(abstractSyntaxTree: any, nodes?: any[]): any[] {
  nodes = nodes || [];

  if (!_.isArray(abstractSyntaxTree) && _.isObject(abstractSyntaxTree) && abstractSyntaxTree.type && _.isUndefined(abstractSyntaxTree.nodeID)) {
    abstractSyntaxTree.nodeID = nodes.length;
    nodes.push(abstractSyntaxTree);
  }

  Object.freeze(abstractSyntaxTree);
  
  _.forOwn(abstractSyntaxTree, (childNode, i) => {
    if (childNode instanceof Object && !(childNode instanceof Array)) {
      collectFrozenNodes(childNode, nodes);
    } else if (childNode instanceof Array) {
      _.forEach(childNode, (arrayChild) => {
        if (arrayChild instanceof Object && !(arrayChild instanceof Array)) {
          collectFrozenNodes(arrayChild, nodes);
        }
      });
    }
  });

  return nodes;
};
Example #4
0
 constructor(options: ITool<T>) {
     
   _.assign(this, options);
   
   if (_.isUndefined(this.lifecycle)) {
     this.lifecycle = Smithy.Lifecycle.Singleton;
   }
   
   assert(_.isString(this.name), "'name' is required and must be a string");
   assert(!_.isUndefined(this.target), "'target' is required");
   assert(!_.isNull(this.target), "'target' is required");
   
   if (!_.isUndefined(this.bindingArguments)) {
     assert(_.isObject(this.bindingArguments), "'bindingArguments', if defined, must be an object.");
   }
   
   if (!_.isUndefined(this.when)) {
     assert(_.isFunction(this.when), "'when', if defined, must be a function.");
   }
   
   if (!_.isUndefined(this.hint)) {
     assert(_.isString(this.hint), "'hint', if defined, must be a string.");
   }
 }
Example #5
0
        (value: boolean | Record<string, boolean>, uiCapability) => {
          if (typeof value === 'boolean') {
            if (!shouldDisableFeatureUICapability(featureId!, uiCapability!)) {
              return value;
            }
            return checkPrivilegesForCapability(value, featureId!, uiCapability!);
          }

          if (isObject(value)) {
            const res = mapValues(value, (enabled, subUiCapability) => {
              return checkPrivilegesForCapability(
                enabled,
                featureId!,
                uiCapability!,
                subUiCapability!
              );
            });
            return res;
          }

          throw new Error(
            `Unexpected UI Capability value. Expected boolean or object, but found ${value}`
          );
        }
Example #6
0
 var checkInputType = function(scope) {
     scope.isObject = _.isObject(scope.input.model);
     scope.isNumber =
         !scope.options &&
         !scope.isObject &&
         (scope.type === "number" || scope.type === "float" || scope.type === "integer");
     scope.isDate = !scope.options && scope.type === "date";
     scope.isText =
         !scope.options &&
         !scope.isObject &&
         !(scope.type === "number" || scope.type === "float" || scope.type === "integer" || scope.type === "label");
     scope.isMultiText = !scope.options && scope.isObject && scope.type !== "label";
     scope.datePicker = {
         options: YleinenData.dateOptions,
         format: YleinenData.dateFormatDatepicker,
         state: false,
         open: function($event) {
             $event.preventDefault();
             $event.stopPropagation();
             scope.datePicker.state = !scope.datePicker.state;
         }
     };
     scope.isLabel = scope.type === "label";
 };
        var uusiViesti = function(tyyppi, viesti, ilmanKuvaa = false) {
            if (_.isObject(viesti) && viesti.data && viesti.data.syy) {
                viesti = viesti.data.syy;
            } else if (!viesti) {
                viesti = "";
            }

            if (!_.isEmpty(viestit)) {
                var viimeinenViesti = viestit[_.size(viestit) - 1];
                if (viimeinenViesti.tyyppi === tyyppi && viimeinenViesti.viesti === viesti) {
                    return;
                }
            }

            viestit.push({
                viesti: viesti ? viesti : tyyppi === 1 ? "tallennus-onnistui" : "",
                ilmanKuvaa: ilmanKuvaa,
                tyyppi: tyyppi,
                luotu: new Date()
            });

            $rootScope.$broadcast("update:notifikaatiot");
            refresh();
        };
Example #8
0
    .service("virheService", function($state) {
        var data = {};

        return {
            setData(d) {
                data = d;
            },

            getData() {
                return data;
            },

            virhe(virhe) {
                if (_.isObject(virhe)) {
                    data = virhe;
                } else {
                    data = { muu: virhe };
                }
                $state.go("root.virhe", {
                    location: "replace"
                });
            }
        };
    });
            function mandatoryFieldValidator(fields, target) {
                err = undefined;
                const fieldsf = _.filter(fields || [], function(field) {
                    return (field as any).mandatory;
                });

                $rootScope.$$ekEditing = false;

                if (!target) {
                    return false;
                } else if (_.isString(target)) {
                    return !_.isEmpty(target);
                } else if (_.isObject(target) && !_.isEmpty(target) && !_.isEmpty(fieldsf)) {
                    return _.all(fieldsf, function(field: any) {
                        var valid = Utils.hasLocalizedText(target[field.path]);
                        if (!valid) {
                            err = field.mandatoryMessage;
                        }
                        return valid;
                    });
                } else {
                    return true;
                }
            }
Example #10
0
			costs: (costs: any) => {
				let cost;
				const errors: any[] = [];
				for (const fileType of keys(costs)) {
					cost = costs[fileType];
					if (!fileTypes.exists(fileType)) {
						errors.push({
							path: fileType,
							message: 'Invalid file type. Valid file types are: ["' + fileTypes.names.join('", "') + '"].',
							setting: fileType,
						});
					}
					if (!isNumber(cost) && !isObject(cost)) {
						errors.push({
							path: fileType,
							message: 'Cost must be an integer or object.',
							setting: cost,
						});
					}
				}
				if (errors.length > 0) {
					return errors;
				}
			},