How to use @nakedobjects/restful-objects - 10 common examples

To help you get started, we’ve selected a few @nakedobjects/restful-objects examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github NakedObjectsGroup / NakedObjectsFramework / Spa2 / nakedobjectsspa / cicero / src / cicero-commands / enter.ts View on Github external
private handleFreeForm(field: Ro.IField, fieldEntry: string) {
        if (field.isScalar()) {

            const mandatoryError = validateMandatory(field, fieldEntry);

            if (mandatoryError) {
                return this.returnResult('', this.validationMessage(mandatoryError, new Ro.Value(''), field.extensions().friendlyName()));
            }

            let value = new Ro.Value(fieldEntry);
            if (Ro.isDateOrDateTime(field)) {
                const dt = validateDate(fieldEntry, supportedDateFormats);

                if (dt) {
                    value = new Ro.Value(Ro.toDateString(dt.toDate()));
                }
            }

            // if optional but empty always valid
            if (fieldEntry != null && fieldEntry !== '') {

                const remoteMask = field.extensions().mask();
                const localFilter = this.mask.toLocalFilter(remoteMask, field.extensions().format()!);

                const validateError = validateMandatoryAgainstType(field, fieldEntry, localFilter);

                if (validateError) {
                    return this.returnResult('', this.validationMessage(validateError, value, field.extensions().friendlyName()));
                }
            }
github NakedObjectsGroup / NakedObjectsFramework / Spa2 / nakedobjectsspa / cicero / src / cicero-commands / enter.ts View on Github external
private updateOnMatches(field: Ro.IField, allFields: Ro.IField[], fieldEntry: string, matches: Ro.Value[]) {
        switch (matches.length) {
            case 0:
            case 1:
                const match = matches.length === 0 ? new Ro.Value(null) : matches[0];
                // TODO fix "!""
                return this.setFieldAndCheckDependencies(field, allFields, match).then((crs: CommandResult[]) => last(crs)!);
            default:
                // shouldn't happen - ignore
                return this.returnResult('', '');
        }
    }
github NakedObjectsGroup / NakedObjectsFramework / Spa2 / nakedobjectsspa / cicero / src / cicero-commands / enter.ts View on Github external
private handleFreeForm(field: Ro.IField, fieldEntry: string) {
        if (field.isScalar()) {

            const mandatoryError = validateMandatory(field, fieldEntry);

            if (mandatoryError) {
                return this.returnResult('', this.validationMessage(mandatoryError, new Ro.Value(''), field.extensions().friendlyName()));
            }

            let value = new Ro.Value(fieldEntry);
            if (Ro.isDateOrDateTime(field)) {
                const dt = validateDate(fieldEntry, supportedDateFormats);

                if (dt) {
                    value = new Ro.Value(Ro.toDateString(dt.toDate()));
                }
            }

            // if optional but empty always valid
            if (fieldEntry != null && fieldEntry !== '') {

                const remoteMask = field.extensions().mask();
                const localFilter = this.mask.toLocalFilter(remoteMask, field.extensions().format()!);

                const validateError = validateMandatoryAgainstType(field, fieldEntry, localFilter);
github NakedObjectsGroup / NakedObjectsFramework / Spa2 / nakedobjectsspa / view-models / src / domain-object-view-model.ts View on Github external
const selfAsValue = (): Ro.Value | null => {
            const link = this.domainObject.selfLink();
            if (link) {
                // not transient - can't drag transients so no need to set up IDraggable members on transients
                link.setTitle(this.title);
                return new Ro.Value(link);
            }
            return null;
        };
        const sav = selfAsValue();
github NakedObjectsGroup / NakedObjectsFramework / Spa2 / nakedobjectsspa / cicero / src / cicero-commands / enter.ts View on Github external
private handleFreeForm(field: Ro.IField, fieldEntry: string) {
        if (field.isScalar()) {

            const mandatoryError = validateMandatory(field, fieldEntry);

            if (mandatoryError) {
                return this.returnResult('', this.validationMessage(mandatoryError, new Ro.Value(''), field.extensions().friendlyName()));
            }

            let value = new Ro.Value(fieldEntry);
            if (Ro.isDateOrDateTime(field)) {
                const dt = validateDate(fieldEntry, supportedDateFormats);

                if (dt) {
                    value = new Ro.Value(Ro.toDateString(dt.toDate()));
                }
            }

            // if optional but empty always valid
            if (fieldEntry != null && fieldEntry !== '') {

                const remoteMask = field.extensions().mask();
                const localFilter = this.mask.toLocalFilter(remoteMask, field.extensions().format()!);
github NakedObjectsGroup / NakedObjectsFramework / Spa2 / nakedobjectsspa / gemini / src / field / field.component.ts View on Github external
then((cvms: ChoiceViewModel[]) => {
                    // if unchanged return
                    if (cvms.length === this.currentOptions.length && every(cvms, (c, i) => c.equals(this.currentOptions[i]))) {
                        return;
                    }
                    this.model.choices = cvms;
                    this.currentOptions = cvms;

                    if (this.isConditionalChoices) {
                        // need to reset control to find the selected options
                        if (this.model.entryType === Ro.EntryType.MultipleConditionalChoices) {
                            this.control.reset(this.model.selectedMultiChoices);
                        } else {
                            this.control.reset(this.model.selectedChoice);
                        }
                    }
                }).
                catch(() => {
github NakedObjectsGroup / NakedObjectsFramework / Spa2 / nakedobjectsspa / services / src / context.service.ts View on Github external
private doPrompt = (field: Ro.IField, id: string, searchTerm: string | null, setupPrompt: (map: Ro.PromptMap) => void, objectValues: () => Dictionary, digest?: string | null) => {
        const promptMap = field.getPromptMap() as Ro.PromptMap; // not null
        promptMap.setMembers(objectValues);
        setupPrompt(promptMap);
        const addEmptyOption = field.entryType() !== Ro.EntryType.AutoComplete && field.extensions().optional();
        return this.repLoader.retrieve(promptMap, Ro.PromptRepresentation, digest).then((p: Ro.PromptRepresentation) => p.choices(addEmptyOption));
    }
github NakedObjectsGroup / NakedObjectsFramework / Spa2 / nakedobjectsspa / view-models / src / table-row-column-view-model.ts View on Github external
this.returnType = 'string';
            }

            if (propertyRep instanceof Ro.PropertyMember) {
                const isPassword = propertyRep.extensions().dataType() === 'password';
                const value = propertyRep.value();
                this.returnType = propertyRep.extensions().returnType()!;

                if (propertyRep.isScalar()) {
                    this.type = 'scalar';
                    Helpers.setScalarValueInView(this, propertyRep, value);

                    const remoteMask = propertyRep.extensions().mask();
                    const localFilter = mask.toLocalFilter(remoteMask, propertyRep.extensions().format()!);

                    if (propertyRep.entryType() === Ro.EntryType.Choices) {
                        const currentChoice = new ChoiceViewModel(value, id);
                        const choicesMap = propertyRep.choices()!;
                        const choices = map(choicesMap, (v, n) => new ChoiceViewModel(v, id, n));
                        const choice = find(choices, c => c.valuesEqual(currentChoice));

                        if (choice) {
                            this.value = choice.name;
                            this.formattedValue = choice.name;
                        }
                    } else if (isPassword) {
                        this.formattedValue = Msg.obscuredText;
                    } else {
                        this.formattedValue = localFilter.filter(this.value);
                    }
                } else {
                    // is reference
github NakedObjectsGroup / NakedObjectsFramework / Spa2 / nakedobjectsspa / gemini / src / object / object.component.ts View on Github external
protected setup(routeData: PaneRouteData) {
        // subscription means may get with no oid

        if (!routeData.objectId) {
            this.mode = null;
            return;
        }

        this.expiredTransient = false;

        const oid = Ro.ObjectIdWrapper.fromObjectId(routeData.objectId, this.configService.config.keySeparator);

        if (this.object && !this.object.domainObject.getOid().isSame(oid)) {
            // object has changed - clear existing
            this.clearCurrentObject();
        }

        const isChanging = !this.object;

        const modeChanging = this.mode !== routeData.interactionMode;

        this.mode = routeData.interactionMode;

        const wasDirty = this.isDirty(routeData, oid);

        this.selectedDialogId = routeData.dialogId;
github NakedObjectsGroup / NakedObjectsFramework / Spa2 / nakedobjectsspa / services / src / rep-loader.service.ts View on Github external
error = errorRep;
            } else {
                return this.handleInvalidResponse(ErrorCategory.HttpServerError);
            }
        } else if (response.status <= 0) {
            // failed to connect
            category = ErrorCategory.ClientError;
            error = `Failed to connect to server: ${response.url || 'unknown'}`;
        } else {
            category = ErrorCategory.HttpClientError;
            const message = (response.headers && response.headers.get('warning')) || 'Unknown client HTTP error';

            if (response.status === HttpStatusCode.BadRequest ||
                response.status === HttpStatusCode.UnprocessableEntity) {
                // these errors should contain a map
                error = new Ro.ErrorMap(response.error as Ro.IValueMap | Ro.IObjectOfType,
                    response.status,
                    message);
            } else if (response.status === HttpStatusCode.NotFound && this.isObjectUrl(originalUrl)) {
                // were looking for an object an got not found - object may be deleted
                // treat as http problem.
                category = ErrorCategory.HttpClientError;
                error = `Failed to connect to server: ${response.url || 'unknown'}`;
            } else if (response.status === HttpStatusCode.NotFound) {
                // general not found other than object - assume client programming error
                category = ErrorCategory.ClientError;
                error = `Failed to connect to server: ${response.url || 'unknown'}`;
            } else {
                error = message;
            }
        }