hippo-fw 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.dir-locals.el +8 -0
- data/.eslintrc.js +7 -0
- data/.flowconfig +2 -0
- data/.gitignore +22 -0
- data/.jshintrc +3 -0
- data/.rubocop.yml +9 -0
- data/.ruby-version +1 -0
- data/.travis.yml +24 -0
- data/Gemfile +17 -0
- data/Guardfile +19 -0
- data/LICENSE-MIT.txt +21 -0
- data/README.md +36 -0
- data/Rakefile +39 -0
- data/bin/hippo +5 -0
- data/client/extension.js +0 -0
- data/client/hippo/__mocks__/config.js +17 -0
- data/client/hippo/access/index.js +4 -0
- data/client/hippo/access/login-dialog.jsx +38 -0
- data/client/hippo/access/styles.scss +0 -0
- data/client/hippo/boot.jsx +41 -0
- data/client/hippo/components/asset.jsx +81 -0
- data/client/hippo/components/asset.scss +15 -0
- data/client/hippo/components/calendar/Calendar.jsx +25 -0
- data/client/hippo/components/calendar/index.js +3 -0
- data/client/hippo/components/calendar/styles.scss +3 -0
- data/client/hippo/components/data-list.jsx +105 -0
- data/client/hippo/components/data-table.jsx +243 -0
- data/client/hippo/components/data-table/header-cell.jsx +94 -0
- data/client/hippo/components/data-table/table-styles.scss +34 -0
- data/client/hippo/components/enabled.js.erb +5 -0
- data/client/hippo/components/field-validation.js +7 -0
- data/client/hippo/components/form.jsx +65 -0
- data/client/hippo/components/form/field-prop-type.js +16 -0
- data/client/hippo/components/form/fields.jsx +76 -0
- data/client/hippo/components/form/fields/checkbox-wrapper.jsx +21 -0
- data/client/hippo/components/form/fields/date-wrapper.jsx +49 -0
- data/client/hippo/components/form/fields/form-field.scss +4 -0
- data/client/hippo/components/form/fields/select-wrapper.jsx +31 -0
- data/client/hippo/components/form/fields/text-wrapper.jsx +20 -0
- data/client/hippo/components/form/model.js +95 -0
- data/client/hippo/components/form/validations.js +0 -0
- data/client/hippo/components/form/wrapper.jsx +40 -0
- data/client/hippo/components/grid/config.json +3 -0
- data/client/hippo/components/grid/editors.scss +78 -0
- data/client/hippo/components/grid/index.js +2 -0
- data/client/hippo/components/grid/row-editor.scss +74 -0
- data/client/hippo/components/grid/styles.scss +118 -0
- data/client/hippo/components/icon.jsx +70 -0
- data/client/hippo/components/index.js +3 -0
- data/client/hippo/components/modal/index.js +1 -0
- data/client/hippo/components/modal/styles.scss +12 -0
- data/client/hippo/components/network-activity-overlay.jsx +127 -0
- data/client/hippo/components/network-activity-overlay.scss +52 -0
- data/client/hippo/components/query-builder.jsx +157 -0
- data/client/hippo/components/record-finder.jsx +95 -0
- data/client/hippo/components/record-finder/config.json +3 -0
- data/client/hippo/components/record-finder/query-layer.jsx +74 -0
- data/client/hippo/components/record-finder/record-finder.scss +12 -0
- data/client/hippo/components/request-spinner/index.js +1 -0
- data/client/hippo/components/screen.jsx +34 -0
- data/client/hippo/components/select-field/index.js +2 -0
- data/client/hippo/components/select-field/styles.scss +27 -0
- data/client/hippo/components/shared/AssetsListing.jsx +23 -0
- data/client/hippo/components/shared/Checkbox.jsx +49 -0
- data/client/hippo/components/shared/CountBadge.jsx +13 -0
- data/client/hippo/components/shared/DateTime.jsx +58 -0
- data/client/hippo/components/shared/DisplayValue.jsx +15 -0
- data/client/hippo/components/shared/ErrorDisplay.jsx +37 -0
- data/client/hippo/components/shared/FieldMixin.jsx +254 -0
- data/client/hippo/components/shared/FieldSet.jsx +52 -0
- data/client/hippo/components/shared/FieldWrapper.jsx +94 -0
- data/client/hippo/components/shared/FormGroup.jsx +41 -0
- data/client/hippo/components/shared/GenericField.jsx +7 -0
- data/client/hippo/components/shared/IconButton.jsx +13 -0
- data/client/hippo/components/shared/ImageAsset.jsx +78 -0
- data/client/hippo/components/shared/IndeterminateCheckbox.jsx +31 -0
- data/client/hippo/components/shared/Input.jsx +16 -0
- data/client/hippo/components/shared/InputFieldMixin.jsx +78 -0
- data/client/hippo/components/shared/JobProgress.jsx +46 -0
- data/client/hippo/components/shared/NumberInput.jsx +37 -0
- data/client/hippo/components/shared/PanelHeader.jsx +15 -0
- data/client/hippo/components/shared/RadioField.jsx +33 -0
- data/client/hippo/components/shared/ResizeSensor.jsx +18 -0
- data/client/hippo/components/shared/ScreenWrapper.jsx +17 -0
- data/client/hippo/components/shared/TextArea.jsx +19 -0
- data/client/hippo/components/shared/Throbber.jsx +8 -0
- data/client/hippo/components/shared/ToggleField.jsx +2 -0
- data/client/hippo/components/shared/Tooltip.jsx +23 -0
- data/client/hippo/components/shared/fields.scss +58 -0
- data/client/hippo/components/shared/fieldset.scss +27 -0
- data/client/hippo/components/shared/image-asset.scss +53 -0
- data/client/hippo/components/shared/index.js +5 -0
- data/client/hippo/components/shared/overlay.scss +83 -0
- data/client/hippo/components/shared/resize-sensor.scss +30 -0
- data/client/hippo/components/shared/styles.scss +64 -0
- data/client/hippo/components/shared/throbber.scss +53 -0
- data/client/hippo/components/toolbar/changes-notification.scss +63 -0
- data/client/hippo/components/toolbar/index.js +3 -0
- data/client/hippo/components/toolbar/styles.scss +74 -0
- data/client/hippo/components/warning-notification.jsx +14 -0
- data/client/hippo/config.js +72 -0
- data/client/hippo/extensions/EarlyExtensions.js.erb +3 -0
- data/client/hippo/extensions/LateLoaded.js.erb +4 -0
- data/client/hippo/extensions/base.js +23 -0
- data/client/hippo/extensions/hippo.js +11 -0
- data/client/hippo/extensions/index.js +47 -0
- data/client/hippo/extensions/namespace-available.js.erb +3 -0
- data/client/hippo/fonts/fontawesome-webfont.woff +0 -0
- data/client/hippo/fonts/fontawesome-webfont.woff2 +0 -0
- data/client/hippo/index.js +1 -0
- data/client/hippo/index.scss.erb +31 -0
- data/client/hippo/lib/__mocks__/loader.js +11 -0
- data/client/hippo/lib/__mocks__/request-assets.js +6 -0
- data/client/hippo/lib/all.js +14 -0
- data/client/hippo/lib/bootstrap.js +45 -0
- data/client/hippo/lib/index.js.erb +6 -0
- data/client/hippo/lib/loader.js +67 -0
- data/client/hippo/lib/request-assets.js +38 -0
- data/client/hippo/lib/smooth-scroll.js +68 -0
- data/client/hippo/lib/util.js +101 -0
- data/client/hippo/models/PubSub.js +208 -0
- data/client/hippo/models/__mocks__/sync.js +17 -0
- data/client/hippo/models/asset.js +104 -0
- data/client/hippo/models/base.js +142 -0
- data/client/hippo/models/collection.js +58 -0
- data/client/hippo/models/decorators.js +72 -0
- data/client/hippo/models/index.js +10 -0
- data/client/hippo/models/query.js +116 -0
- data/client/hippo/models/query/array-result.js +188 -0
- data/client/hippo/models/query/clause.js +52 -0
- data/client/hippo/models/query/field.js +63 -0
- data/client/hippo/models/query/info.js +43 -0
- data/client/hippo/models/query/operator.js +21 -0
- data/client/hippo/models/query/result.js +21 -0
- data/client/hippo/models/query/types.js +5 -0
- data/client/hippo/models/sync.js +135 -0
- data/client/hippo/models/system-setting.js +26 -0
- data/client/hippo/react/DefaultComponentNotFound.jsx +23 -0
- data/client/hippo/react/Root.jsx +24 -0
- data/client/hippo/react/index.js +7 -0
- data/client/hippo/react/viewport-root.jsx +44 -0
- data/client/hippo/screens/all.js.erb +3 -0
- data/client/hippo/screens/definition.js +67 -0
- data/client/hippo/screens/group.js +35 -0
- data/client/hippo/screens/index.js +34 -0
- data/client/hippo/screens/instance.js +99 -0
- data/client/hippo/screens/mixins/index.js +0 -0
- data/client/hippo/screens/register.js.erb +14 -0
- data/client/hippo/screens/styles.scss +8 -0
- data/client/hippo/screens/system-settings.jsx +92 -0
- data/client/hippo/screens/system-settings/mailer-config.jsx +53 -0
- data/client/hippo/screens/system-settings/system-settings.scss +8 -0
- data/client/hippo/screens/user-management.jsx +67 -0
- data/client/hippo/screens/user-management/edit-form.jsx +94 -0
- data/client/hippo/screens/user-management/index.scss +7 -0
- data/client/hippo/styles/fonts.scss +23 -0
- data/client/hippo/styles/fonts/_animated.scss +34 -0
- data/client/hippo/styles/fonts/_bordered-pulled.scss +25 -0
- data/client/hippo/styles/fonts/_core.scss +12 -0
- data/client/hippo/styles/fonts/_fixed-width.scss +6 -0
- data/client/hippo/styles/fonts/_icons.scss +789 -0
- data/client/hippo/styles/fonts/_larger.scss +13 -0
- data/client/hippo/styles/fonts/_list.scss +19 -0
- data/client/hippo/styles/fonts/_mixins.scss +60 -0
- data/client/hippo/styles/fonts/_path.scss +10 -0
- data/client/hippo/styles/fonts/_rotated-flipped.scss +20 -0
- data/client/hippo/styles/fonts/_screen-reader.scss +5 -0
- data/client/hippo/styles/fonts/_stacked.scss +20 -0
- data/client/hippo/styles/fonts/_variables.scss +800 -0
- data/client/hippo/styles/fonts/font-awesome.scss +18 -0
- data/client/hippo/styles/fonts/index.scss +2 -0
- data/client/hippo/styles/global.scss +3 -0
- data/client/hippo/styles/global/fancy-header.scss +14 -0
- data/client/hippo/styles/global/mixins.scss +5 -0
- data/client/hippo/styles/global/styles.scss +6 -0
- data/client/hippo/styles/variables.scss +28 -0
- data/client/hippo/testing/index.js +6 -0
- data/client/hippo/testing/matchers.js +14 -0
- data/client/hippo/testing/mocks/fetch.js +54 -0
- data/client/hippo/testing/screens.js +64 -0
- data/client/hippo/testing/utils.js +1 -0
- data/client/hippo/user.js +93 -0
- data/client/hippo/workspace/content.jsx +22 -0
- data/client/hippo/workspace/foo.js +0 -0
- data/client/hippo/workspace/index.jsx +85 -0
- data/client/hippo/workspace/menu-group.jsx +39 -0
- data/client/hippo/workspace/menu-option.jsx +41 -0
- data/client/hippo/workspace/menu.jsx +71 -0
- data/client/hippo/workspace/navbar.jsx +46 -0
- data/client/hippo/workspace/screen.jsx +50 -0
- data/client/hippo/workspace/styles.scss +61 -0
- data/client/hippo/workspace/styles/forms.scss +4 -0
- data/client/hippo/workspace/styles/header.scss +69 -0
- data/client/hippo/workspace/styles/keybindings.scss +6 -0
- data/client/hippo/workspace/styles/layout.scss +230 -0
- data/client/hippo/workspace/styles/screens.scss +15 -0
- data/client/hippo/workspace/styles/tabs.scss +141 -0
- data/client/hippo/workspace/tabs.jsx +60 -0
- data/client/hippo/workspace/viewport.jsx +82 -0
- data/client/images/hippo/ajax-loader.gif +0 -0
- data/client/images/hippo/logo-sm.png +0 -0
- data/coffeelint.json +49 -0
- data/command-reference-files/initial/.babelrc +20 -0
- data/command-reference-files/initial/.eslintrc.js +7 -0
- data/command-reference-files/initial/.gitignore +4 -0
- data/command-reference-files/initial/.rubocop.yml +9 -0
- data/command-reference-files/initial/Gemfile +9 -0
- data/command-reference-files/initial/Guardfile +13 -0
- data/command-reference-files/initial/Rakefile +2 -0
- data/command-reference-files/initial/client/appy-app/components/.gitkeep +0 -0
- data/command-reference-files/initial/client/appy-app/extension.js +32 -0
- data/command-reference-files/initial/client/appy-app/index.js +6 -0
- data/command-reference-files/initial/client/appy-app/models/.gitkeep +0 -0
- data/command-reference-files/initial/client/appy-app/models/base.js +11 -0
- data/command-reference-files/initial/client/appy-app/screens/.gitkeep +0 -0
- data/command-reference-files/initial/client/appy-app/styles.scss +1 -0
- data/command-reference-files/initial/config.ru +7 -0
- data/command-reference-files/initial/config/database.yml +11 -0
- data/command-reference-files/initial/config/initialize.rb +10 -0
- data/command-reference-files/initial/config/jest.config.json +19 -0
- data/command-reference-files/initial/config/jest/babel-transform.js +47 -0
- data/command-reference-files/initial/config/routes.rb +4 -0
- data/command-reference-files/initial/config/screens.rb +10 -0
- data/command-reference-files/initial/config/webpack.config.js +106 -0
- data/command-reference-files/initial/db/.gitkeep +0 -0
- data/command-reference-files/initial/lib/appy-app.rb +15 -0
- data/command-reference-files/initial/lib/appy-app/extension.rb +22 -0
- data/command-reference-files/initial/lib/appy-app/model.rb +11 -0
- data/command-reference-files/initial/lib/appy-app/version.rb +3 -0
- data/command-reference-files/initial/package.json +6 -0
- data/command-reference-files/initial/spec/client/.eslintrc.js +20 -0
- data/command-reference-files/initial/spec/client/setup.js +17 -0
- data/command-reference-files/initial/spec/server/spec_helper.rb +8 -0
- data/command-reference-files/initial/views/index.html +69 -0
- data/command-reference-files/model/client/appy-app/models/test_test.js +12 -0
- data/command-reference-files/model/config/routes.rb +4 -0
- data/command-reference-files/model/db/migrate/20150218032025_create_test_tests.rb +10 -0
- data/command-reference-files/model/lib/appy-app/model.rb +12 -0
- data/command-reference-files/model/lib/appy-app/models/test_test.rb +7 -0
- data/command-reference-files/model/spec/client/models/test_test.spec.js +8 -0
- data/command-reference-files/model/spec/fixtures/appy-app/test_test.yml +11 -0
- data/command-reference-files/model/spec/server/test_test_spec.rb +10 -0
- data/command-reference-files/screen/client/appy-app/extension.js +32 -0
- data/command-reference-files/screen/client/appy-app/screens/ready-set-go.jsx +22 -0
- data/command-reference-files/screen/config/screens.rb +19 -0
- data/command-reference-files/screen/spec/client/screens/ready-set-go.spec.jsx +12 -0
- data/config.ru +5 -0
- data/config/database.yml +9 -0
- data/config/jest.config.json +27 -0
- data/config/jest/babel-transform.js +47 -0
- data/config/jest/style-mock.js +2 -0
- data/config/jest/yaml-transform.js +19 -0
- data/config/routes.rb +28 -0
- data/config/screens.rb +42 -0
- data/config/webpack.config.js +105 -0
- data/db/migrate/01_create_system_settings.rb +10 -0
- data/db/migrate/02_create_assets.rb +13 -0
- data/db/migrate/20140615031600_create_users.rb +12 -0
- data/db/seed.rb +1 -0
- data/docs/command.md +114 -0
- data/docs/model.md +217 -0
- data/docs/react.md +137 -0
- data/docs/todo-example-part-1.md +69 -0
- data/docs/welcome.md +0 -0
- data/hippo-fw.gemspec +79 -0
- data/lib/generators/hippo/migrations/install_generator.rb +42 -0
- data/lib/hippo-fw.rb +1 -0
- data/lib/hippo.rb +34 -0
- data/lib/hippo/access.rb +49 -0
- data/lib/hippo/access/authentication_provider.rb +79 -0
- data/lib/hippo/access/config/database.yml +9 -0
- data/lib/hippo/access/config/routes.rb +20 -0
- data/lib/hippo/access/locked_fields.rb +43 -0
- data/lib/hippo/access/public/files/1nty/7ebo/n7k0/8b2ac0bbd97f401951fe40546f977200.png +0 -0
- data/lib/hippo/access/public/files/6hgp/eiw1/8dua/ba944287e36e101713a9c1ad793353b8.png +0 -0
- data/lib/hippo/access/public/files/94bd/9agc/2ua3/33800e285d7145760650ac88d1c558fb.png +0 -0
- data/lib/hippo/access/public/files/cr1e/vfwc/fvrh/0e7fe6ef12d622bfb93e024883c2f81c.png +0 -0
- data/lib/hippo/access/public/files/kezo/fm8j/u6xl/dfc47658aedd8e546abff63366a7285d.png +0 -0
- data/lib/hippo/access/public/files/n5c4/uovf/jec6/7ee9a3519e2b60430e095160a23f1d77.png +0 -0
- data/lib/hippo/access/role.rb +86 -0
- data/lib/hippo/access/role_collection.rb +88 -0
- data/lib/hippo/access/roles/administrator.rb +32 -0
- data/lib/hippo/access/roles/basic_user.rb +13 -0
- data/lib/hippo/access/roles/support.rb +15 -0
- data/lib/hippo/access/test_fixture_extensions.rb +16 -0
- data/lib/hippo/access/track_modifications.rb +79 -0
- data/lib/hippo/access/version.rb +5 -0
- data/lib/hippo/api.rb +23 -0
- data/lib/hippo/api/cable.rb +57 -0
- data/lib/hippo/api/controller_base.rb +299 -0
- data/lib/hippo/api/default_routes.rb +38 -0
- data/lib/hippo/api/error_formatter.rb +37 -0
- data/lib/hippo/api/formatted_reply.rb +62 -0
- data/lib/hippo/api/generic_controller.rb +35 -0
- data/lib/hippo/api/handlers/asset.rb +38 -0
- data/lib/hippo/api/handlers/print.rb +15 -0
- data/lib/hippo/api/handlers/user_session.rb +42 -0
- data/lib/hippo/api/helper_methods.rb +58 -0
- data/lib/hippo/api/pub_sub.rb +36 -0
- data/lib/hippo/api/request_wrapper.rb +105 -0
- data/lib/hippo/api/root.rb +70 -0
- data/lib/hippo/api/routing.rb +111 -0
- data/lib/hippo/api/sprockets_extension.rb +105 -0
- data/lib/hippo/api/to_json.rb +7 -0
- data/lib/hippo/api/updates.rb +37 -0
- data/lib/hippo/asset.rb +18 -0
- data/lib/hippo/capistrano.rb +30 -0
- data/lib/hippo/cli.rb +50 -0
- data/lib/hippo/command.rb +43 -0
- data/lib/hippo/command/app.rb +90 -0
- data/lib/hippo/command/client_config.rb +69 -0
- data/lib/hippo/command/client_model_update.rb +65 -0
- data/lib/hippo/command/console.rb +23 -0
- data/lib/hippo/command/db.rb +36 -0
- data/lib/hippo/command/db.usage +1 -0
- data/lib/hippo/command/generate.rb +24 -0
- data/lib/hippo/command/generate_component.rb +28 -0
- data/lib/hippo/command/generate_component.usage +11 -0
- data/lib/hippo/command/generate_migration.rb +33 -0
- data/lib/hippo/command/generate_model.rb +91 -0
- data/lib/hippo/command/generate_model.usage +45 -0
- data/lib/hippo/command/generate_screen.rb +40 -0
- data/lib/hippo/command/generate_screen.usage +8 -0
- data/lib/hippo/command/guard.rb +18 -0
- data/lib/hippo/command/jest.rb +40 -0
- data/lib/hippo/command/migration_support.rb +29 -0
- data/lib/hippo/command/model_attribute.rb +193 -0
- data/lib/hippo/command/named_command.rb +33 -0
- data/lib/hippo/command/puma.rb +56 -0
- data/lib/hippo/command/server.rb +19 -0
- data/lib/hippo/command/server.usage +3 -0
- data/lib/hippo/command/update.rb +13 -0
- data/lib/hippo/command/update_model.rb +127 -0
- data/lib/hippo/command/update_model.usage +2 -0
- data/lib/hippo/command/webpack.rb +57 -0
- data/lib/hippo/command/webpack_view.rb +32 -0
- data/lib/hippo/concerns/all.rb +15 -0
- data/lib/hippo/concerns/api_path.rb +21 -0
- data/lib/hippo/concerns/asset_uploader.rb +38 -0
- data/lib/hippo/concerns/association_extensions.rb +94 -0
- data/lib/hippo/concerns/attr_accessor_with_default.rb +68 -0
- data/lib/hippo/concerns/code_identifier.rb +43 -0
- data/lib/hippo/concerns/export_associations.rb +52 -0
- data/lib/hippo/concerns/export_join_tables.rb +39 -0
- data/lib/hippo/concerns/export_methods.rb +104 -0
- data/lib/hippo/concerns/export_scope.rb +64 -0
- data/lib/hippo/concerns/exported_limit_evaluator.rb +17 -0
- data/lib/hippo/concerns/pub_sub.rb +127 -0
- data/lib/hippo/concerns/queries.rb +24 -0
- data/lib/hippo/concerns/random_identifier.rb +37 -0
- data/lib/hippo/concerns/sanitize_fields.rb +32 -0
- data/lib/hippo/concerns/set_attribute_data.rb +125 -0
- data/lib/hippo/concerns/sorting_expressions.rb +34 -0
- data/lib/hippo/configuration.rb +143 -0
- data/lib/hippo/db.rb +57 -0
- data/lib/hippo/db/migrations.rb +32 -0
- data/lib/hippo/environment.rb +22 -0
- data/lib/hippo/extension.rb +112 -0
- data/lib/hippo/extension/definition.rb +90 -0
- data/lib/hippo/guard_tasks.rb +62 -0
- data/lib/hippo/hippo_guard_plugin.rb +80 -0
- data/lib/hippo/job.rb +82 -0
- data/lib/hippo/job/failure_logger.rb +33 -0
- data/lib/hippo/logger.rb +64 -0
- data/lib/hippo/mailer.rb +28 -0
- data/lib/hippo/model.rb +24 -0
- data/lib/hippo/multi_server_boot.rb +26 -0
- data/lib/hippo/numbers.rb +72 -0
- data/lib/hippo/rails_engine.rb +5 -0
- data/lib/hippo/rake_tasks.rb +69 -0
- data/lib/hippo/redis.rb +13 -0
- data/lib/hippo/reloadable_sinatra.rb +24 -0
- data/lib/hippo/reloadable_view.rb +13 -0
- data/lib/hippo/screen.rb +152 -0
- data/lib/hippo/spec_helper.rb +141 -0
- data/lib/hippo/strings.rb +56 -0
- data/lib/hippo/system_settings.rb +72 -0
- data/lib/hippo/templates/base.rb +44 -0
- data/lib/hippo/templates/latex.rb +101 -0
- data/lib/hippo/templates/liquid.rb +28 -0
- data/lib/hippo/user.rb +152 -0
- data/lib/hippo/validators/all.rb +2 -0
- data/lib/hippo/validators/email.rb +17 -0
- data/lib/hippo/validators/set.rb +18 -0
- data/lib/hippo/version.rb +5 -0
- data/lib/hippo/workspace.rb +4 -0
- data/lib/hippo/workspace/config/screens.rb +6 -0
- data/package.json +82 -0
- data/spec/client/.eslintrc.js +20 -0
- data/spec/client/access/login-dialog.spec.jsx +28 -0
- data/spec/client/components/__snapshots__/asset.spec.jsx.snap +48 -0
- data/spec/client/components/__snapshots__/network-activity-overlay.spec.jsx.snap +35 -0
- data/spec/client/components/__snapshots__/query-builder.spec.jsx.snap +82 -0
- data/spec/client/components/asset.spec.jsx +16 -0
- data/spec/client/components/data-list.spec.jsx +36 -0
- data/spec/client/components/data-table.spec.jsx +55 -0
- data/spec/client/components/form.spec.jsx +63 -0
- data/spec/client/components/network-activity-overlay.spec.jsx +30 -0
- data/spec/client/components/query-builder.spec.jsx +45 -0
- data/spec/client/components/record-finder.spec.jsx +45 -0
- data/spec/client/extension/base.spec.js +15 -0
- data/spec/client/lib/util.spec.js +48 -0
- data/spec/client/models/asset.spec.js +50 -0
- data/spec/client/models/base.spec.js +95 -0
- data/spec/client/models/collection.spec.js +51 -0
- data/spec/client/models/query.spec.js +243 -0
- data/spec/client/models/sync.spec.js +42 -0
- data/spec/client/models/system-setting.spec.js +19 -0
- data/spec/client/screens/__snapshots__/system-settings.spec.jsx.snap +364 -0
- data/spec/client/screens/__snapshots__/tabs.spec.jsx.snap +127 -0
- data/spec/client/screens/definition.spec.js +24 -0
- data/spec/client/screens/group.spec.js +33 -0
- data/spec/client/screens/instance.spec.js +61 -0
- data/spec/client/screens/system-settings.spec.jsx +22 -0
- data/spec/client/screens/tabs.spec.jsx +36 -0
- data/spec/client/screens/user-management.spec.jsx +48 -0
- data/spec/client/setup.js +12 -0
- data/spec/client/test-logo.json +41 -0
- data/spec/client/test-models.js +94 -0
- data/spec/client/user.spec.js +19 -0
- data/spec/client/workspace/__snapshots__/menu.spec.jsx.snap +380 -0
- data/spec/client/workspace/menu.spec.jsx +52 -0
- data/spec/factories/user.rb +11 -0
- data/spec/fixtures/logo.png +0 -0
- data/spec/fixtures/system_settings.yml +8 -0
- data/spec/fixtures/test_printer.tex +22 -0
- data/spec/fixtures/user.yml +2 -0
- data/spec/hippo/components/grid/GridSpec.coffee +56 -0
- data/spec/hippo/components/grid/PopoverEditorSpec.coffee +47 -0
- data/spec/hippo/components/grid/RowEditorSpec.coffee +98 -0
- data/spec/hippo/components/select-field/SelectFieldSpec.coffee +106 -0
- data/spec/hippo/components/shared/NetworkActivityOverlaySpec.coffee +34 -0
- data/spec/hippo/helpers/.gitkeep +0 -0
- data/spec/hippo/helpers/hippo-helpers.coffee +5 -0
- data/spec/hippo/helpers/jasmine-matchers.js +1580 -0
- data/spec/hippo/helpers/mock-ajax.js +573 -0
- data/spec/hippo/models/AssociationMapSpec.coffee +85 -0
- data/spec/hippo/models/AssociationProxySpec.coffee +76 -0
- data/spec/hippo/models/BaseSpec.coffee +155 -0
- data/spec/hippo/models/CollectionSpec.coffee +32 -0
- data/spec/hippo/models/EnumMapSpec.coffee +26 -0
- data/spec/hippo/models/PubSubSpec.coffee +71 -0
- data/spec/hippo/models/QuerySpec.coffee +19 -0
- data/spec/hippo/models/SyncSpec.coffee +28 -0
- data/spec/hippo/models/UserSpec.coffee +17 -0
- data/spec/hippo/react/mixins/DataSpec.coffee +74 -0
- data/spec/hippo/screens/DefinitionsSpec.coffee +33 -0
- data/spec/hippo/views/BaseSpec.coffee +147 -0
- data/spec/hippo/views/FormBindingsSpec.coffee +32 -0
- data/spec/server/api/controller_base_spec.rb +101 -0
- data/spec/server/assertions.rb +11 -0
- data/spec/server/asset_spec.rb +42 -0
- data/spec/server/command_spec.rb +73 -0
- data/spec/server/concerns/api_path_spec.rb +20 -0
- data/spec/server/concerns/association_extensions_spec.rb +24 -0
- data/spec/server/concerns/attr_accessor_with_default_spec.rb +63 -0
- data/spec/server/concerns/export_methods_spec.rb +34 -0
- data/spec/server/concerns/export_scope_spec.rb +14 -0
- data/spec/server/concerns/exported_limits_spec.rb +51 -0
- data/spec/server/concerns/pub_sub_spec.rb +132 -0
- data/spec/server/concerns/set_attribute_data_spec.rb +76 -0
- data/spec/server/concerns/sorting_expressions_spec.rb +34 -0
- data/spec/server/concerns/track_modifications_spec.rb +18 -0
- data/spec/server/configuration_spec.rb +26 -0
- data/spec/server/job_spec.rb +54 -0
- data/spec/server/mailer_spec.rb +33 -0
- data/spec/server/numbers_spec.rb +25 -0
- data/spec/server/print/form_spec.rb +29 -0
- data/spec/server/spec_helper.rb +74 -0
- data/spec/server/strings_spec.rb +41 -0
- data/spec/server/system_settings_spec.rb +39 -0
- data/tasks/migrations.rake +22 -0
- data/tasks/publish.rake +8 -0
- data/templates/.babelrc +20 -0
- data/templates/.gitignore +4 -0
- data/templates/Gemfile +9 -0
- data/templates/Guardfile +13 -0
- data/templates/Rakefile +2 -0
- data/templates/client/components/.gitkeep +0 -0
- data/templates/client/components/BaseComponent.coffee +9 -0
- data/templates/client/components/Component.cjsx +4 -0
- data/templates/client/components/template.html +3 -0
- data/templates/client/extension.js +32 -0
- data/templates/client/index.js +6 -0
- data/templates/client/models/base.js +11 -0
- data/templates/client/models/model.js +17 -0
- data/templates/client/screens/screen.jsx +22 -0
- data/templates/client/styles.scss +1 -0
- data/templates/config.ru +7 -0
- data/templates/config/database.yml +11 -0
- data/templates/config/initialize.rb +10 -0
- data/templates/config/jest.config.json +19 -0
- data/templates/config/jest/babel-transform.js +47 -0
- data/templates/config/routes.rb +4 -0
- data/templates/config/screen.rb +9 -0
- data/templates/config/screens.rb +10 -0
- data/templates/config/webpack.config.js +106 -0
- data/templates/db/create_table_migration.rb +19 -0
- data/templates/gitignore +4 -0
- data/templates/js/config-data.js +10 -0
- data/templates/js/jest.config.json +11 -0
- data/templates/js/root-view.html +71 -0
- data/templates/js/screen-definitions.js +22 -0
- data/templates/lib/namespace.rb +15 -0
- data/templates/lib/namespace/base_model.rb +11 -0
- data/templates/lib/namespace/extension.rb +22 -0
- data/templates/lib/namespace/model.rb +7 -0
- data/templates/lib/namespace/version.rb +3 -0
- data/templates/public/.gitkeep +0 -0
- data/templates/spec/client/components/ComponentSpec.coffee +5 -0
- data/templates/spec/client/models/model.spec.js +8 -0
- data/templates/spec/client/screen.spec.jsx +12 -0
- data/templates/spec/client/setup.js +17 -0
- data/templates/spec/fixtures/namespace/model.yml +16 -0
- data/templates/spec/server/model_spec.rb +10 -0
- data/templates/spec/server/spec_helper.rb +8 -0
- data/test.js +7 -0
- data/views/hippo_root_view.erb +68 -0
- data/views/index.html +71 -0
- data/yard_ext/all.rb +9 -0
- data/yard_ext/code_identifier_handler.rb +33 -0
- data/yard_ext/concern_meta_methods.rb +60 -0
- data/yard_ext/config_options.rb +27 -0
- data/yard_ext/exported_scope.rb +4 -0
- data/yard_ext/immutable_handler.rb +17 -0
- data/yard_ext/json_attr_accessor.rb +22 -0
- data/yard_ext/locked_fields_handler.rb +21 -0
- data/yard_ext/templates/default/layout/html/layout.erb +20 -0
- data/yard_ext/templates/default/method_details/html/github_link.erb +1 -0
- data/yard_ext/templates/default/method_details/setup.rb +3 -0
- data/yard_ext/validators.rb +1 -0
- data/yard_ext/visible_id_handler.rb +38 -0
- data/yarn.lock +6562 -0
- metadata +1182 -0
@@ -0,0 +1,17 @@
|
|
1
|
+
/* global jest */
|
2
|
+
|
3
|
+
let nextResponse = {
|
4
|
+
success: true,
|
5
|
+
data: {},
|
6
|
+
message: 'success',
|
7
|
+
};
|
8
|
+
|
9
|
+
export default {
|
10
|
+
forModel: jest.fn(() => Promise.resolve(nextResponse)),
|
11
|
+
forCollection: jest.fn(() => Promise.resolve(nextResponse)),
|
12
|
+
perform: jest.fn(() => Promise.resolve(nextResponse)),
|
13
|
+
|
14
|
+
setResponseData(response) {
|
15
|
+
nextResponse = response;
|
16
|
+
},
|
17
|
+
};
|
@@ -0,0 +1,104 @@
|
|
1
|
+
import { includes, get, isEmpty } from 'lodash';
|
2
|
+
import qs from 'qs';
|
3
|
+
import { observe } from 'mobx';
|
4
|
+
import {
|
5
|
+
BaseModel, identifiedBy, field, session, identifier, computed,
|
6
|
+
} from './base';
|
7
|
+
import Config from '../config';
|
8
|
+
|
9
|
+
const IMAGES = [
|
10
|
+
'image/png', 'image/jpeg', 'image/gif',
|
11
|
+
];
|
12
|
+
|
13
|
+
const IS_IMAGE = content_type => !!(content_type && (-1 !== IMAGES.indexOf(content_type)));
|
14
|
+
|
15
|
+
const UPDATE_METHODS = { POST: true, PUT: true, PATCH: true };
|
16
|
+
|
17
|
+
@identifiedBy('hippo/asset')
|
18
|
+
export default class Asset extends BaseModel {
|
19
|
+
|
20
|
+
@identifier id;
|
21
|
+
@field order;
|
22
|
+
@session file_data;
|
23
|
+
|
24
|
+
@session file;
|
25
|
+
|
26
|
+
@session({ type: 'object' }) file_data;
|
27
|
+
@session metadata;
|
28
|
+
|
29
|
+
@field({ type: 'object' }) owner;
|
30
|
+
@field owner_association_name;
|
31
|
+
|
32
|
+
constructor(props) {
|
33
|
+
super(props);
|
34
|
+
|
35
|
+
observe(this, 'owner', ({ newValue: owner }) => {
|
36
|
+
if (this.ownerSaveDisposer) { this.ownerSaveDisposer(); }
|
37
|
+
if (!owner || !owner.isModel) { return; }
|
38
|
+
this.ownerSaveDisposer = observe(owner, 'syncInProgress', ({ newValue, oldValue }) => {
|
39
|
+
if (this.isDirty &&
|
40
|
+
!this.syncInProgress &&
|
41
|
+
!oldValue &&
|
42
|
+
newValue && newValue.isUpdate
|
43
|
+
) {
|
44
|
+
newValue.whenComplete(() => this.save());
|
45
|
+
}
|
46
|
+
});
|
47
|
+
}, true);
|
48
|
+
}
|
49
|
+
|
50
|
+
@computed get baseUrl() {
|
51
|
+
return Config.api_host + Config.api_path + Config.assets_path_prefix;
|
52
|
+
}
|
53
|
+
|
54
|
+
@computed get isDirty() {
|
55
|
+
return !!this.file;
|
56
|
+
}
|
57
|
+
|
58
|
+
@computed get isImage() {
|
59
|
+
return includes(IMAGES, this.mimeType);
|
60
|
+
}
|
61
|
+
|
62
|
+
@computed get mimeType() {
|
63
|
+
return get(
|
64
|
+
this, 'file.type',
|
65
|
+
get(this, 'file_data.original.metadata.mime_type'),
|
66
|
+
);
|
67
|
+
}
|
68
|
+
|
69
|
+
@computed get previewUrl() {
|
70
|
+
return get(this, 'file.preview', this.urlFor('thumbnail'));
|
71
|
+
}
|
72
|
+
|
73
|
+
urlFor(type = 'original') {
|
74
|
+
const url = get(this, `file_data.${type}.id`);
|
75
|
+
return url ? `${this.baseUrl}/${url}` : null;
|
76
|
+
}
|
77
|
+
|
78
|
+
save() {
|
79
|
+
if (!this.file) { return Promise.resolve(this); }
|
80
|
+
const form = new FormData();
|
81
|
+
|
82
|
+
if (this.id) { form.append('id', this.id); }
|
83
|
+
form.append('file', this.file, this.file.name);
|
84
|
+
form.append('owner_type', this.owner.constructor.identifiedBy);
|
85
|
+
form.append('owner_id', this.owner.identifierFieldValue);
|
86
|
+
form.append('owner_association', this.owner_association_name);
|
87
|
+
|
88
|
+
let url = `${Config.api_path}${Config.assets_path_prefix}`;
|
89
|
+
const query = {};
|
90
|
+
if (Config.access_token) {
|
91
|
+
query.jwt = Config.access_token;
|
92
|
+
}
|
93
|
+
if (!isEmpty(query)) {
|
94
|
+
url += `?${qs.stringify(query, { arrayFormat: 'brackets' })}`;
|
95
|
+
}
|
96
|
+
return fetch(url, { method: 'POST', body: form })
|
97
|
+
.then(resp => resp.json())
|
98
|
+
.then((json) => {
|
99
|
+
this.file = undefined;
|
100
|
+
return json;
|
101
|
+
}).then(json => this.set(json.data));
|
102
|
+
}
|
103
|
+
|
104
|
+
}
|
@@ -0,0 +1,142 @@
|
|
1
|
+
import PropTypes from 'prop-types';
|
2
|
+
import {
|
3
|
+
findModel,
|
4
|
+
} from 'mobx-decorated-models';
|
5
|
+
import invariant from 'invariant';
|
6
|
+
import {
|
7
|
+
isEmpty, isNil, find, extend, assign, pick, map, isArray,
|
8
|
+
} from 'lodash';
|
9
|
+
|
10
|
+
import { action, observable, computed } from 'mobx';
|
11
|
+
|
12
|
+
import pluralize from 'pluralize';
|
13
|
+
|
14
|
+
import Sync from './sync';
|
15
|
+
import Config from '../config';
|
16
|
+
import { toSentence, humanize } from '../lib/util';
|
17
|
+
import ModelCollection from './collection';
|
18
|
+
|
19
|
+
export {
|
20
|
+
identifiedBy, belongsTo, hasMany,
|
21
|
+
} from 'mobx-decorated-models';
|
22
|
+
export {
|
23
|
+
action, autorun,
|
24
|
+
} from 'mobx';
|
25
|
+
export {
|
26
|
+
field, session, identifier,
|
27
|
+
} from './decorators';
|
28
|
+
|
29
|
+
export {
|
30
|
+
observable, computed,
|
31
|
+
};
|
32
|
+
|
33
|
+
export class BaseModel {
|
34
|
+
|
35
|
+
static get propType() {
|
36
|
+
return PropTypes.instanceOf(this);
|
37
|
+
}
|
38
|
+
|
39
|
+
static findDerived(name) {
|
40
|
+
return findModel(name);
|
41
|
+
}
|
42
|
+
|
43
|
+
static get assignableKeys() {
|
44
|
+
return this.$schema.keys();
|
45
|
+
}
|
46
|
+
|
47
|
+
static get propertyOptions() {
|
48
|
+
const options = {};
|
49
|
+
this.$schema.forEach((val, name) => (options[name] = val.options));
|
50
|
+
return options;
|
51
|
+
}
|
52
|
+
|
53
|
+
static get syncUrl() {
|
54
|
+
invariant(this.identifiedBy, 'must have an identifiedBy property in order to calulate syncUrl');
|
55
|
+
return `${Config.api_path}/${pluralize(this.identifiedBy)}`;
|
56
|
+
}
|
57
|
+
|
58
|
+
static get identifierFieldName() {
|
59
|
+
const field = find(this.$schema.values(), { type: 'identifier' });
|
60
|
+
invariant(field, 'identifierFieldName called on a model that has not designated one with `@identifier`');
|
61
|
+
return field.name;
|
62
|
+
}
|
63
|
+
|
64
|
+
static get Collection() {
|
65
|
+
return this.$collection || (this.$collection = new ModelCollection(this));
|
66
|
+
}
|
67
|
+
|
68
|
+
constructor(attrs) {
|
69
|
+
if (!isEmpty(attrs)) { this.set(attrs); }
|
70
|
+
}
|
71
|
+
|
72
|
+
get isModel() { return true; }
|
73
|
+
|
74
|
+
@observable syncInProgress = false;
|
75
|
+
@observable lastServerMessage = '';
|
76
|
+
@observable errors = {};
|
77
|
+
|
78
|
+
@computed get errorMessage() {
|
79
|
+
return this.errors ? toSentence(map(this.errors, (v, k) => `${humanize(k)} ${v}`)) : '';
|
80
|
+
}
|
81
|
+
|
82
|
+
@computed get isValid() {
|
83
|
+
return isNil(this.errors) || isEmpty(this.errors);
|
84
|
+
}
|
85
|
+
|
86
|
+
@computed get isNew() {
|
87
|
+
return isNil(this.identifierFieldValue);
|
88
|
+
}
|
89
|
+
|
90
|
+
@computed get identifierFieldValue() {
|
91
|
+
return this[this.constructor.identifierFieldName];
|
92
|
+
}
|
93
|
+
|
94
|
+
@computed get syncUrl() {
|
95
|
+
const path = this.constructor.syncUrl;
|
96
|
+
return this.isNew ? path : `${path}/${this.identifierFieldValue}`;
|
97
|
+
}
|
98
|
+
|
99
|
+
set(attrs = {}) {
|
100
|
+
assign(this, pick(attrs, this.constructor.assignableKeys));
|
101
|
+
return this;
|
102
|
+
}
|
103
|
+
|
104
|
+
@action reset() {
|
105
|
+
this.constructor.assignableKeys.forEach(k => (this[k] = null));
|
106
|
+
}
|
107
|
+
|
108
|
+
set syncData(data) {
|
109
|
+
if (!data) { return this; }
|
110
|
+
if (isArray(data) && data.length) {
|
111
|
+
this.update(data[0]);
|
112
|
+
} else {
|
113
|
+
this.update(data);
|
114
|
+
}
|
115
|
+
return this;
|
116
|
+
}
|
117
|
+
|
118
|
+
@computed
|
119
|
+
get syncData() {
|
120
|
+
return this.serialize();
|
121
|
+
}
|
122
|
+
|
123
|
+
fetch(options = {}) {
|
124
|
+
invariant((!this.isNew || options.query),
|
125
|
+
'Unable to fetch record without it’s identifier being set or a query');
|
126
|
+
const fetchOptions = extend(options, { limit: 1, method: 'GET' });
|
127
|
+
if (!fetchOptions.query) {
|
128
|
+
fetchOptions.query = { [`${this.constructor.identifierFieldName}`]: this.identifierFieldValue };
|
129
|
+
}
|
130
|
+
return Sync.forModel(this, fetchOptions);
|
131
|
+
}
|
132
|
+
|
133
|
+
save(options = {}) {
|
134
|
+
return Sync.forModel(this, options);
|
135
|
+
}
|
136
|
+
|
137
|
+
destroy(options = {}) {
|
138
|
+
return Sync.forModel(this, extend(options, { action: 'destroy' }));
|
139
|
+
}
|
140
|
+
}
|
141
|
+
|
142
|
+
export default BaseModel;
|
@@ -0,0 +1,58 @@
|
|
1
|
+
import { observable } from 'mobx';
|
2
|
+
import invariant from 'invariant';
|
3
|
+
import { extend, each, isArray, isObject, isEmpty } from 'lodash';
|
4
|
+
import { createCollection } from 'mobx-decorated-models';
|
5
|
+
|
6
|
+
import Sync from './sync';
|
7
|
+
|
8
|
+
function extendAry(modelClass, models = [], options = {}) {
|
9
|
+
invariant(isArray(models), 'models must be an array');
|
10
|
+
const ary = createCollection(extend({ model: modelClass }, options));
|
11
|
+
|
12
|
+
if (models.length) {
|
13
|
+
ary.replace(models);
|
14
|
+
}
|
15
|
+
|
16
|
+
ary.$map = observable.map({
|
17
|
+
lastServerMessage: '',
|
18
|
+
syncInProgress: '',
|
19
|
+
errors: {},
|
20
|
+
});
|
21
|
+
ary.$map.keys().forEach((prop) => {
|
22
|
+
Object.defineProperty(ary, prop, {
|
23
|
+
get() { return this.$map.get(prop); },
|
24
|
+
set(val) { return this.$map.set(prop, val); },
|
25
|
+
});
|
26
|
+
});
|
27
|
+
Object.defineProperties(ary, {
|
28
|
+
syncUrl: {
|
29
|
+
get() { return modelClass.syncUrl; },
|
30
|
+
},
|
31
|
+
syncData: {
|
32
|
+
set(rows) {
|
33
|
+
this.replace(rows);
|
34
|
+
},
|
35
|
+
},
|
36
|
+
});
|
37
|
+
ary.fetch = function(fetchOptions = {}) {
|
38
|
+
return Sync.forCollection(this, fetchOptions);
|
39
|
+
};
|
40
|
+
if (options.fetch) {
|
41
|
+
ary.fetch(isObject(options.fetch) ? options.fetch : {});
|
42
|
+
}
|
43
|
+
return ary;
|
44
|
+
}
|
45
|
+
|
46
|
+
export default class ModelCollection {
|
47
|
+
constructor(model) {
|
48
|
+
this.$model = model;
|
49
|
+
this.$collection = extendAry(model, [], {}, this);
|
50
|
+
return this;
|
51
|
+
}
|
52
|
+
create(models = [], options = {}) {
|
53
|
+
if (isObject(models) && isEmpty(options)) {
|
54
|
+
return extendAry(this.$model, [], models, this);
|
55
|
+
}
|
56
|
+
return extendAry(this.$model, models, options, this);
|
57
|
+
}
|
58
|
+
}
|
@@ -0,0 +1,72 @@
|
|
1
|
+
import {
|
2
|
+
isEmpty, isArray, isNumber, isObject, isString, partial, defaults, isNil, isDate,
|
3
|
+
} from 'lodash';
|
4
|
+
import invariant from 'invariant';
|
5
|
+
|
6
|
+
import { intercept, isObservableArray, isObservableObject } from 'mobx';
|
7
|
+
|
8
|
+
import {
|
9
|
+
field as mobxField,
|
10
|
+
session as mobxSession,
|
11
|
+
identifier as mobxIdentifier,
|
12
|
+
} from 'mobx-decorated-models';
|
13
|
+
|
14
|
+
const VALIDATORS = {
|
15
|
+
number: isNumber,
|
16
|
+
string: isString,
|
17
|
+
array(a) { return isArray(a) || isObservableArray(a); },
|
18
|
+
object(o) { return isObject(o) || isObservableObject(o); },
|
19
|
+
date: isDate,
|
20
|
+
};
|
21
|
+
|
22
|
+
const COERCE = {
|
23
|
+
date(change) {
|
24
|
+
if (!isDate(change.newValue)) {
|
25
|
+
change.newValue = new Date(change.newValue); // eslint-disable-line no-param-reassign
|
26
|
+
}
|
27
|
+
},
|
28
|
+
};
|
29
|
+
|
30
|
+
function addLazyInitializer(target, fn) {
|
31
|
+
target.__mobxLazyInitializers.push(fn);
|
32
|
+
}
|
33
|
+
|
34
|
+
function validateChangeType(validator, propertyName, change) {
|
35
|
+
if (isNil(change.newValue)) { return change; }
|
36
|
+
invariant(VALIDATORS[validator], `Unknown TypeCheck: ${validator} does not exist`);
|
37
|
+
if (COERCE[validator]) { COERCE[validator](change); }
|
38
|
+
invariant(VALIDATORS[validator](change.newValue),
|
39
|
+
`Bad Type: Attempted to set ${propertyName} to '${change.newValue}' which is not ${validator}`);
|
40
|
+
return change;
|
41
|
+
}
|
42
|
+
|
43
|
+
function addTypeSafeInterceptor(target, property, type) {
|
44
|
+
if (isEmpty(type)) { return; }
|
45
|
+
addLazyInitializer(target, (partial(intercept, partial.placeholder, property,
|
46
|
+
partial(validateChangeType, type, property))));
|
47
|
+
}
|
48
|
+
|
49
|
+
function decoratorWrapper(decorator, defaultOptions = {}) {
|
50
|
+
return (targetOrOptions, ...args) => {
|
51
|
+
const options = isEmpty(args) ?
|
52
|
+
defaults(targetOrOptions, defaultOptions) : defaultOptions;
|
53
|
+
|
54
|
+
const wrap = (target, property, descriptor) => {
|
55
|
+
const decorationFn = decorator(options);
|
56
|
+
const description = decorationFn(target, property, descriptor);
|
57
|
+
addTypeSafeInterceptor(target, property, options.type);
|
58
|
+
return description;
|
59
|
+
};
|
60
|
+
|
61
|
+
if (isEmpty(args)) { // we were given options
|
62
|
+
return (target, property, descriptor) => wrap(target, property, descriptor);
|
63
|
+
}
|
64
|
+
return wrap(targetOrOptions, args[0], args[1]);
|
65
|
+
};
|
66
|
+
}
|
67
|
+
|
68
|
+
const field = decoratorWrapper(mobxField);
|
69
|
+
const session = decoratorWrapper(mobxSession);
|
70
|
+
const identifier = decoratorWrapper(mobxIdentifier, { type: 'number' });
|
71
|
+
|
72
|
+
export { field, session, identifier };
|
@@ -0,0 +1,116 @@
|
|
1
|
+
import { get, isString, find, extend, toPairs } from 'lodash';
|
2
|
+
import { action, reaction, observe } from 'mobx';
|
3
|
+
import {
|
4
|
+
BaseModel, identifiedBy, field, belongsTo, hasMany, identifier, computed, session,
|
5
|
+
} from './base';
|
6
|
+
|
7
|
+
import Info from './query/info';
|
8
|
+
import Types from './query/types';
|
9
|
+
import Operator from './query/operator';
|
10
|
+
import Clause from './query/clause';
|
11
|
+
import Field from './query/field';
|
12
|
+
import ArrayResult from './query/array-result';
|
13
|
+
|
14
|
+
// needs to inherit from Base so network events will be listened to
|
15
|
+
@identifiedBy('hippo/query')
|
16
|
+
export default class Query extends BaseModel {
|
17
|
+
|
18
|
+
@belongsTo src;
|
19
|
+
|
20
|
+
@identifier id;
|
21
|
+
@session pageSize = 20;
|
22
|
+
|
23
|
+
@session initialField;
|
24
|
+
@session idIndex;
|
25
|
+
@session initialFieldIndex;
|
26
|
+
|
27
|
+
@session sortField;
|
28
|
+
@session sortAscending = false;
|
29
|
+
|
30
|
+
@session results;
|
31
|
+
@session customSyncUrl;
|
32
|
+
|
33
|
+
@session autoFetch = false;
|
34
|
+
|
35
|
+
@field({ type: 'object' }) syncOptions = {};
|
36
|
+
|
37
|
+
@hasMany({ model: Clause, inverseOf: 'query' }) clauses;
|
38
|
+
@hasMany({ model: Operator, inverseOf: 'query' }) operators;
|
39
|
+
@hasMany({ model: Field, inverseOf: 'query' }) fields;
|
40
|
+
|
41
|
+
@action
|
42
|
+
setSort({ field: f, ascending }) {
|
43
|
+
this.sortField = f;
|
44
|
+
this.sortAscending = ascending;
|
45
|
+
}
|
46
|
+
|
47
|
+
constructor(attrs = {}) {
|
48
|
+
for (let i = 0; i < get(attrs, 'fields.length', 0); i += 1) {
|
49
|
+
if (isString(attrs.fields[i])) {
|
50
|
+
attrs.fields[i] = { id: attrs.fields[i] }; // eslint-disable-line no-param-reassign
|
51
|
+
}
|
52
|
+
}
|
53
|
+
super(attrs);
|
54
|
+
[
|
55
|
+
{ id: 'like', label: 'Starts With', types: Types.LIKE_QUERY_TYPES },
|
56
|
+
{ id: 'eq', label: 'Equals' },
|
57
|
+
{ id: 'lt', label: 'Less Than', types: Types.LESS_THAN_QUERY_TYPES },
|
58
|
+
{ id: 'gt', label: 'More Than', types: Types.LESS_THAN_QUERY_TYPES },
|
59
|
+
].forEach(op => this.operators.push(op));
|
60
|
+
this.info = new Info(this);
|
61
|
+
this.results = new ArrayResult({ query: this });
|
62
|
+
if (0 === this.clauses.length) {
|
63
|
+
this.clauses.push({ });
|
64
|
+
}
|
65
|
+
if (attrs.sort) {
|
66
|
+
const [fieldId, dir] = toPairs(attrs.sort)[0];
|
67
|
+
this.sortField = find(this.fields, { id: fieldId });
|
68
|
+
this.sortAscending = ('ASC' === dir);
|
69
|
+
}
|
70
|
+
observe(this, 'autoFetch', this._onAutoFetchChange);
|
71
|
+
}
|
72
|
+
|
73
|
+
@computed get fingerprint() {
|
74
|
+
return this.clauses.map(o => o.fingerprint).join(';');
|
75
|
+
}
|
76
|
+
|
77
|
+
open() {
|
78
|
+
if (this.autoFetch) { this._startAutoFetch(); }
|
79
|
+
}
|
80
|
+
|
81
|
+
close() {
|
82
|
+
if (this.autoFetchDisposer) {
|
83
|
+
this.autoFetchDisposer();
|
84
|
+
this.autoFetchDisposer = undefined;
|
85
|
+
}
|
86
|
+
}
|
87
|
+
|
88
|
+
@action.bound
|
89
|
+
fetch() {
|
90
|
+
return this.results.fetch({ start: 0 });
|
91
|
+
}
|
92
|
+
|
93
|
+
fetchSingle(query, queryOptions = {}) {
|
94
|
+
const options = extend(queryOptions, this.syncOptions, { query });
|
95
|
+
const { src: Src } = this;
|
96
|
+
const model = new Src();
|
97
|
+
return model.fetch(options);
|
98
|
+
}
|
99
|
+
|
100
|
+
@action.bound
|
101
|
+
_onAutoFetchChange(change) {
|
102
|
+
if (change.newValue) {
|
103
|
+
this._startAutoFetch();
|
104
|
+
} else if (this.autoFetchDisposer) {
|
105
|
+
this.autoFetchDisposer();
|
106
|
+
}
|
107
|
+
}
|
108
|
+
|
109
|
+
_startAutoFetch() {
|
110
|
+
this.autoFetchDisposer = reaction(
|
111
|
+
() => this.fingerprint,
|
112
|
+
this.fetch,
|
113
|
+
{ delay: 100, compareStructural: true, fireImmediately: true },
|
114
|
+
);
|
115
|
+
}
|
116
|
+
}
|