json-schema-builder icon indicating copy to clipboard operation
json-schema-builder copied to clipboard

Defining the "Basic Usage"

Open ThomasPe opened this issue 9 years ago • 8 comments

So we can work towards a common goal I'd like to discuss how exactly the Json Schema Builder should be used / called / included. I created a small "Basic Usage" example based on the Angular Schema Form Example. As I see it, it should be enough to just have a $scope.schema and a $scope.form (and an optional $scope.options) object for passing & receiving data, right?

Here's what I think it could look like (from my fork)

First, expose your (existing) schema and form to the $scope.

angular.module('myModule', ['schemaFormBuilder'])
       .controller('FormBuilderController', function($scope) {
  // JSON Schema
  // add an existing schema to edit it
  // or leave blank to create a new form
  $scope.schema = {};

  // Schema Form Defintion
  // add an existing form definition for editing
  // or leave blank to create a new form
  $scope.form = [];


});

Then load them into the Schema Form Builder using the sfbSchema and sfbForm directives.

<div ng-controller="FormBuilderController">
    <div sfb-schema="schema" sfb-form="form"></form>
</div>

Thoughts?

ThomasPe avatar Apr 19 '16 12:04 ThomasPe

Well, yeah, something like that would be the usage, I suppose. As close as the normal ASF usage as possible.

Have you looked closer to see if it easy to break out a directive from the application?

nicklasb avatar Apr 19 '16 14:04 nicklasb

Took a quick look, and the code seems really nice, it should be pretty easy to break that out.

nicklasb avatar Apr 19 '16 14:04 nicklasb

I'm currently working on that. There's some functionality in there that does not belong into the library IMHO, like saving forms or notifying the user of changes (locker, growl). But the code is well-structured, so it's certainly possible. I'll have to read up on some angular convetions & best practices first, though.

ThomasPe avatar Apr 19 '16 14:04 ThomasPe

Please do, it would be a killer feature if you could get that done.

nicklasb avatar Apr 19 '16 14:04 nicklasb

I'm gonna need this for my masters thesis, so eventually I'll have to ;-)

ThomasPe avatar Apr 19 '16 14:04 ThomasPe

Good choice. :-)

nicklasb avatar Apr 19 '16 14:04 nicklasb

I'm partial to: https://github.com/johnpapa/angular-styleguide The material repo also has a jscs file that follows Google code guide with minor differences, but I haven't looked into the builder enough to know how appropriate that is, however it would be nice to follow the same guides across all js implementations within the org. That's my 2c :)

Anthropic avatar Apr 19 '16 14:04 Anthropic

Thanks, I'll give it a look and try to abide by it.

ThomasPe avatar Apr 19 '16 15:04 ThomasPe