Permalink
Browse files

doc: Content-Sample works

  • Loading branch information...
MikeMitterer committed Nov 21, 2018
0 parents commit 960f32be7d5b69c85259a06d04fc9caf817d9ce3
Showing with 2,374 additions and 0 deletions.
  1. +2 −0 .deploySamples.sh.conf
  2. +34 −0 LICENSE
  3. +7 −0 README.md
  4. +14 −0 analysis_options.yaml
  5. +47 −0 build.jenkins
  6. +43 −0 dart_test.yaml
  7. +47 −0 lib/content/MaterialContoller.dart
  8. +119 −0 lib/content/ViewFactory.dart
  9. +121 −0 lib/content/components/MaterialContent.dart
  10. +111 −0 lib/content/components/MaterialInclude.dart
  11. +83 −0 lib/m4d_content.dart
  12. +46 −0 pubspec.yaml
  13. +87 −0 samples/_scripts/.prep.default.kts
  14. +95 −0 samples/_templates/default.app.scss
  15. +96 −0 samples/_templates/default.index.html
  16. +21 −0 samples/_templates/pubspec.tmpl.yaml
  17. +8 −0 samples/m4d_content/.prep.config.properties
  18. +1 −0 samples/m4d_content/.prep.kts
  19. +15 −0 samples/m4d_content/.rsync
  20. +74 −0 samples/m4d_content/.sitegen/html/_content/index.html
  21. +2 −0 samples/m4d_content/.sitegen/site.yaml
  22. +117 −0 samples/m4d_content/lib/components/ListComponent.dart
  23. +4 −0 samples/m4d_content/lib/components/interfaces/SimpleDataObject.dart
  24. +51 −0 samples/m4d_content/lib/m4d_content_sample.dart
  25. +25 −0 samples/m4d_content/pubspec.yaml
  26. +95 −0 samples/m4d_content/web/_app.scss
  27. +34 −0 samples/m4d_content/web/demo.scss
  28. +101 −0 samples/m4d_content/web/includes/store.dart
  29. +159 −0 samples/m4d_content/web/index.html
  30. +210 −0 samples/m4d_content/web/main.dart
  31. +3 −0 samples/m4d_content/web/views/home.html
  32. +32 −0 samples/m4d_content/web/views/slider.html
  33. +3 −0 samples/m4d_content/web/views/test.html
  34. +14 −0 samples/m4d_content/web/views/test2.html
  35. +8 −0 samples/m4d_include/.prep.config.properties
  36. +1 −0 samples/m4d_include/.prep.kts
  37. +15 −0 samples/m4d_include/.rsync
  38. +15 −0 samples/m4d_include/.sitegen/html/_content/index.html
  39. +86 −0 samples/m4d_include/.sitegen/html/_templates/default.html
  40. +2 −0 samples/m4d_include/.sitegen/site.yaml
  41. +21 −0 samples/m4d_include/pubspec.yaml
  42. +95 −0 samples/m4d_include/web/_app.scss
  43. +16 −0 samples/m4d_include/web/demo.scss
  44. +107 −0 samples/m4d_include/web/index.html
  45. +27 −0 samples/m4d_include/web/main.dart
  46. +3 −0 samples/m4d_include/web/views/home.html
  47. +31 −0 samples/m4d_include/web/views/slider.html
  48. +23 −0 samples/m4d_include/web/views/test.html
  49. +3 −0 samples/m4d_include/web/views/test2.html
@@ -0,0 +1,2 @@
WEB_DESCRIPTION="Material 4 Dart / Content"
WEB_PACKAGE="m4d_content"
34 LICENSE
@@ -0,0 +1,34 @@
Copyright (c) 2018, Michael Mitterer (office@mikemitterer.at),
IT-Consulting and Development Limited.

All Rights Reserved.

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

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Michael Mitterer, IT-Consulting
and Development Limited, Austrian Branch, nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL Michael Mitterer,
IT-Consulting and Development Limited, Austrian Branch, BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,7 @@
# Material 4 Dart - Content / Include

## Examples
> [GitHub](https://github.com/MikeMitterer/m4d_content)


@@ -0,0 +1,14 @@
analyzer:
# exclude:
# - path/to/excluded/files/**

# Lint rules and documentation, see http://dart-lang.github.io/linter/lints
linter:
rules:
- cancel_subscriptions
- hash_and_equals
- iterable_contains_unrelated_type
- list_remove_unrelated_type
- test_types_in_equals
- unrelated_type_equality_checks
- valid_regexps
@@ -0,0 +1,47 @@
pipeline {
agent {
label 'linux'
}
stages {
stage('Preparation') {
steps {
timeout(time: 15, unit: 'MINUTES') {
ansiColor('xterm') {
sh 'pub update'
}
}

}
}
stage('Analyze') {
steps {
ansiColor('xterm') {
sh 'dartanalyzer lib/'
// sh 'dartanalyzer test/'
}
}
}
/*
stage('Test') {
steps {
ansiColor('xterm') {
sh 'pub run test test -p chrome'
}
}
}
*/
stage('Deploy samples') {
steps {
timeout(time: 30, unit: 'MINUTES') {
ansiColor('xterm') {
sh 'deploySamples.sh --prepare'
sh 'deploySamples.sh --update'
sh 'deploySamples.sh --deploy --release'
sh 'deploySamples.sh --publish --force'
}
}
}
}
}
}

@@ -0,0 +1,43 @@
# Browser-Based project - Test chrome by default.
platforms: [ chrome ]

paths:
- test

#define_platforms:
# # This identifier is used to select the platform with the --platform flag.
# chromium:
# # A human-friendly name for the platform.
# name: Chromium
#
# # The identifier for the platform that this is based on.
# extends: chrome
#
# # Settings for the new child platform.
# settings:
# executable:
# linux: chromium-browser
# mac_os: /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
#
# # Funkt nicht: --headless
# # https://github.com/dart-lang/test/issues/730
# arguments: --window-position=5000,5000 --window-size=1,1 --disable-gpu
#

override_platforms:
chrome:
settings:
headless: false
# Funkt nicht: --headless
# https://github.com/dart-lang/test/issues/730
#arguments: --window-position=5000,5000 --window-size=1,1 --disable-gpu
arguments: --window-position=10,0 --window-size=1000,800

on_os:
linux:
override_platforms:
chrome:
# The settings to override for this platform.
settings:
executable: chromium-browser
arguments: --window-position=1500,1000 --window-size=2,2 --disable-gpu
@@ -0,0 +1,47 @@
/*
* Copyright (c) 2015, Michael Mitterer (office@mikemitterer.at),
* IT-Consulting and Development Limited.
*
* All Rights Reserved.
*
* 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.
*/

part of m4d_content;

abstract class MaterialController {
/// [iocContainer] will be set after {ViewFactory} receives the {onLoadEnd} Event
ioc.IOCContainer iocContainer;

/// [loaded] is called after [ViewFactory] received the onLoadEnd-Event
///
/// At this point the Template is already rendered
void loaded(final RouteEnterEvent event);

/// Called before the next controller is loaded
void unload() {}
}

class DummyController extends MaterialController {
final Logger _logger = new Logger('mdlapplication.DummyController');

@override
void loaded(final RouteEnterEvent event) {
_logger.info("View loaded! (Route: ${event.route})");
}

@override
void unload() {
_logger.info("Unload Controller...");
}
}
@@ -0,0 +1,119 @@
/*
* Copyright (c) 2015, Michael Mitterer (office@mikemitterer.at),
* IT-Consulting and Development Limited.
*
* All Rights Reserved.
*
* 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.
*/

part of m4d_content;

/**
* Loads additional "views" (html-Page) in SPA-Application
*
* Sample:
* configRouter() {
* final Router router = new Router(useFragment: true);
* final ViewFactory view = new ViewFactory();
*
* router.root
* ..addRoute(name: 'typography', path: '/typography',
* enter: view("views/typography.html", new DemoController()))
*
* ..addRoute(name: 'home', defaultRoute: true, path: '/',
* enter: view("views/home.html" ,new DemoController()))
*
* ;
*
* router.listen();
* }
*
* Until 2017.11.09 ViewFactory was "injectable". This should not be necessary.
* Changing the ViewFactory to a individual version should be very easy without DI.
* See example from above
*/
class ViewFactory {
final Logger _logger = new Logger('mdlremote.ViewFactory');

MaterialController _previousController;

RouteEnterCallback call(final String url, final MaterialController controller, { final String selector: "#main"}) {
return (final RouteEvent event) => _enterHandler(event, url, controller, selector);
}

// void call(final String url, final MaterialController controller, { final String selector: "#main"}) {
// _enterHandler( url, controller, selector);
// }

//- private -----------------------------------------------------------------------------------

void _enterHandler(final RouteEvent event, final String url,
final MaterialController controller, final String selector) {

//Validate.notNull(event);
Validate.notNull(url);
Validate.notNull(controller);
Validate.notBlank(selector);

final Stopwatch stopwatch = new Stopwatch();
final dom.HttpRequest request = new dom.HttpRequest();
final dom.Element contentElement = dom.querySelector(selector);

if(contentElement == null) {
_logger.severe('Please add <div id="$selector" class="mdl-content">Loading...</div> to your index.html');
return;
}

if(_previousController != null) {
_previousController.unload();
}
_previousController = controller;

request.open("GET", url);
request.onLoadEnd.listen((final dom.ProgressEvent progressEvent) {
//_logger.info('Request complete ${request.responseText}, Status: ${request.readyState}');

if (request.readyState == dom.HttpRequest.DONE) {

final String content = sanitizeResponseText(request.responseText);
final MaterialContent main = MaterialContent.widget(contentElement);


// if(controller is ScopeAware) {
// // If you have observable-Properties in your Controller it must be
// // marked as [@mdl.Model]
// // TODO: Check controller if it has a Annotation
// main.scope = (controller as ScopeAware).scope;
// }
// else {
// main.resetScope();
// }

main.render(content).then( (_) {

// TODO: Rename injector to iocContainer
controller.iocContainer = main.injector;
controller.loaded(event);

stopwatch.stop();
_logger.info("Page load and rendering took ${stopwatch.elapsedMilliseconds}ms");
});
}
});

stopwatch.start();
request.send();
}

}
Oops, something went wrong.

0 comments on commit 960f32b

Please sign in to comment.