[DOCUMENTATION] Add linting to tutorial section

Adds code examples with linting
This commit is contained in:
Even Stensberg 2017-01-07 13:49:03 +01:00 committed by GitHub
parent 94319df69b
commit 62685cb892

View File

@ -129,7 +129,7 @@ We will create this file in the directory tutorials/todo (we can hereafter refer
to this plugin as tutorials/todo as well.) We will start with an "empty bundle", to this plugin as tutorials/todo as well.) We will start with an "empty bundle",
one which exposes no extensions - which looks like: one which exposes no extensions - which looks like:
```diff ```js
define([ define([
'openmct' 'openmct'
], function ( ], function (
@ -154,7 +154,7 @@ The tutorials will be updated with the new bundle registration mechanism once it
has been finalized. has been finalized.
#### Before #### Before
```diff ```html
<!-- <!--
Open MCT, Copyright (c) 2014-2016, United States Government Open MCT, Copyright (c) 2014-2016, United States Government
as represented by the Administrator of the National Aeronautics and Space as represented by the Administrator of the National Aeronautics and Space
@ -219,7 +219,7 @@ __index.html__
#### After #### After
```diff ```html
<!-- <!--
Open MCT, Copyright (c) 2014-2016, United States Government Open MCT, Copyright (c) 2014-2016, United States Government
as represented by the Administrator of the National Aeronautics and Space as represented by the Administrator of the National Aeronautics and Space
@ -305,7 +305,7 @@ In the case of our to-do list feature, the to-do list itself is the thing we'll
want users to be able to create and edit. So, we will add that as a new type in want users to be able to create and edit. So, we will add that as a new type in
our bundle definition: our bundle definition:
```diff ```js
define([ define([
'openmct' 'openmct'
], function ( ], function (
@ -369,7 +369,7 @@ directory `tutorials/todo/res/templates` (`res` is, by default, the directory
where bundle-related resources are kept, and `templates` is where HTML templates where bundle-related resources are kept, and `templates` is where HTML templates
are stored by convention.) are stored by convention.)
```diff ```html
<div> <div>
<a href="">All</a> <a href="">All</a>
<a href="">Incomplete</a> <a href="">Incomplete</a>
@ -401,7 +401,7 @@ boolean `completed` flag.
To expose this view in Open MCT, we need to declare it in our bundle To expose this view in Open MCT, we need to declare it in our bundle
definition: definition:
```diff ```js
define([ define([
'openmct' 'openmct'
], function ( ], function (
@ -458,7 +458,7 @@ the user to create these yet. As a temporary workaround to test the view, we
will specify an initial state for To-do List domain object models in the will specify an initial state for To-do List domain object models in the
definition of that type. definition of that type.
```diff ```js
define([ define([
'openmct' 'openmct'
], function ( ], function (
@ -529,7 +529,7 @@ in the directory `tutorials/todo/src/controllers` (`src` is, by default, the
directory where bundle-related source code is kept, and controllers is where directory where bundle-related source code is kept, and controllers is where
Angular controllers are stored by convention.) Angular controllers are stored by convention.)
```diff ```js
define(function () { define(function () {
function TodoController($scope) { function TodoController($scope) {
var showAll = true, var showAll = true,
@ -594,7 +594,7 @@ prior to our template being utilized.
On its own, this controller merely exposes these functions; the next step is to On its own, this controller merely exposes these functions; the next step is to
use them from our template: use them from our template:
```diff ```html
+ <div ng-controller="TodoController"> + <div ng-controller="TodoController">
<div> <div>
+ <a ng-click="setVisibility(true)">All</a> + <a ng-click="setVisibility(true)">All</a>
@ -630,7 +630,7 @@ If we were to try to run at this point, we'd run into problems because the
`TodoController` has not been registered with Angular. We need to first declare `TodoController` has not been registered with Angular. We need to first declare
it in our bundle definition, as an extension of category `controllers`: it in our bundle definition, as an extension of category `controllers`:
```diff ```js
define([ define([
'openmct', 'openmct',
+ './src/controllers/TodoController' + './src/controllers/TodoController'
@ -724,7 +724,7 @@ An Editing user interface is typically handled in a tool bar associated with a
view. The contents of this tool bar are defined declaratively in a view's view. The contents of this tool bar are defined declaratively in a view's
extension definition. extension definition.
```diff ```js
define([ define([
'openmct', 'openmct',
'./src/controllers/TodoController' './src/controllers/TodoController'
@ -813,7 +813,7 @@ all the applicable controls, which means no controls at all.
To support selection, we will need to make some changes to our controller: To support selection, we will need to make some changes to our controller:
```diff ```js
define(function () { define(function () {
+ // Form to display when adding new tasks + // Form to display when adding new tasks
+ var NEW_TASK_FORM = { + var NEW_TASK_FORM = {
@ -928,7 +928,7 @@ Additionally, we need to make changes to our template to select specific tasks
in response to some user gesture. Here, we will select tasks when a user clicks in response to some user gesture. Here, we will select tasks when a user clicks
the description. the description.
```diff ```html
<div ng-controller="TodoController"> <div ng-controller="TodoController">
<div> <div>
<a ng-click="setVisibility(true)">All</a> <a ng-click="setVisibility(true)">All</a>
@ -954,7 +954,7 @@ __tutorials/todo/res/templates/todo.html__
Finally, the `TodoController` uses the `dialogService` now, so we need to Finally, the `TodoController` uses the `dialogService` now, so we need to
declare that dependency in its extension definition: declare that dependency in its extension definition:
```diff ```js
define([ define([
'openmct', 'openmct',
'./src/controllers/TodoController' './src/controllers/TodoController'
@ -1058,7 +1058,7 @@ In this section, our goal is to:
To support the first two, we'll need to expose some methods for checking these To support the first two, we'll need to expose some methods for checking these
states in the controller: states in the controller:
```diff ```js
define(function () { define(function () {
// Form to display when adding new tasks // Form to display when adding new tasks
var NEW_TASK_FORM = { var NEW_TASK_FORM = {
@ -1175,7 +1175,7 @@ states visually, and to generally improve the appearance of our view. We add
another file to the res directory of our bundle; this time, it is `css/todo.css` another file to the res directory of our bundle; this time, it is `css/todo.css`
(with the `css` directory again being a convention.) (with the `css` directory again being a convention.)
```diff ```css
.example-todo div.example-button-group { .example-todo div.example-button-group {
margin-top: 12px; margin-top: 12px;
margin-bottom: 12px; margin-bottom: 12px;
@ -1219,7 +1219,7 @@ To include this CSS file in our running instance of Open MCT, we need to
declare it in our bundle definition, this time as an extension of category declare it in our bundle definition, this time as an extension of category
`stylesheets`: `stylesheets`:
```diff ```js
define([ define([
'openmct', 'openmct',
'./src/controllers/TodoController' './src/controllers/TodoController'
@ -1299,7 +1299,7 @@ To-Do List's type above; now To-Do Lists will start off empty.
Finally, let's utilize these changes from our view's template: Finally, let's utilize these changes from our view's template:
```diff ```html
+ <div ng-controller="TodoController" class="example-todo"> + <div ng-controller="TodoController" class="example-todo">
+ <div class="example-button-group"> + <div class="example-button-group">
+ <a ng-class="{ selected: checkVisibility(true) }" + <a ng-class="{ selected: checkVisibility(true) }"
@ -1359,7 +1359,7 @@ We'll also be defining some custom styles, so we'll include that extension as
well. We'll be creating this plugin in `tutorials/bargraph`, so our initial well. We'll be creating this plugin in `tutorials/bargraph`, so our initial
bundle definition looks like: bundle definition looks like:
```diff ```js
define([ define([
'openmct' 'openmct'
], function ( ], function (
@ -1406,7 +1406,7 @@ For this tutorial, we'll assume that we've sketched out our template and CSS
file ahead of time to describe the general look we want for the view. These file ahead of time to describe the general look we want for the view. These
look like: look like:
```diff ```html
<div class="example-bargraph"> <div class="example-bargraph">
<div class="example-tick-labels"> <div class="example-tick-labels">
<div class="example-tick-label" style="bottom: 0%">High</div> <div class="example-tick-label" style="bottom: 0%">High</div>
@ -1457,7 +1457,7 @@ bar corresponds to which telemetry point. Inline `style` attributes are used
wherever dynamic positioning (handled by a script) is anticipated. wherever dynamic positioning (handled by a script) is anticipated.
The corresponding CSS file which styles and positions these elements: The corresponding CSS file which styles and positions these elements:
```diff ```css
.example-bargraph { .example-bargraph {
position: absolute; position: absolute;
top: 0; top: 0;
@ -1555,7 +1555,7 @@ Notably, we will not try to show telemetry data after this step.
To support this, we will add a new controller which supports our Bar Graph view: To support this, we will add a new controller which supports our Bar Graph view:
```diff ```js
define(function () { define(function () {
function BarGraphController($scope, telemetryHandler) { function BarGraphController($scope, telemetryHandler) {
var handle; var handle;
@ -1607,7 +1607,7 @@ telemetry objects in view, as well as the width for each bar.
We will also utilize this from our template: We will also utilize this from our template:
```diff ```html
+ <div class="example-bargraph" ng-controller="BarGraphController"> + <div class="example-bargraph" ng-controller="BarGraphController">
<div class="example-tick-labels"> <div class="example-tick-labels">
+ <div ng-repeat="value in [low, middle, high] track by $index" + <div ng-repeat="value in [low, middle, high] track by $index"
@ -1660,7 +1660,7 @@ Finally, we expose our controller from our bundle definition. Note that the
depends declaration includes both `$scope` as well as the `telemetryHandler` depends declaration includes both `$scope` as well as the `telemetryHandler`
service we made use of. service we made use of.
```diff ```js
define([ define([
'openmct', 'openmct',
'./src/controllers/BarGraphController' './src/controllers/BarGraphController'
@ -1715,7 +1715,7 @@ First, let's add expose some more functionality from our controller. To make it
simple, we'll expose the top and bottom for a bar graph for a given simple, we'll expose the top and bottom for a bar graph for a given
telemetry-providing domain object, as percentages. telemetry-providing domain object, as percentages.
```diff ```js
define(function () { define(function () {
function BarGraphController($scope, telemetryHandler) { function BarGraphController($scope, telemetryHandler) {
var handle; var handle;
@ -1767,7 +1767,7 @@ decide this.
Next, we utilize this functionality from the template: Next, we utilize this functionality from the template:
```diff ```html
<div class="example-bargraph" ng-controller="BarGraphController"> <div class="example-bargraph" ng-controller="BarGraphController">
<div class="example-tick-labels"> <div class="example-tick-labels">
<div ng-repeat="value in [low, middle, high] track by $index" <div ng-repeat="value in [low, middle, high] track by $index"
@ -1826,7 +1826,7 @@ when we return to our view later, those changes will be persisted.
First, let's add a tool bar for changing these three values in Edit mode: First, let's add a tool bar for changing these three values in Edit mode:
```diff ```js
define([ define([
'openmct', 'openmct',
'./src/controllers/BarGraphController' './src/controllers/BarGraphController'
@ -1900,7 +1900,7 @@ a view proxy to work from. We will add this to our controller, and additionally
will start reading/writing those properties to the view's `configuration` will start reading/writing those properties to the view's `configuration`
object. object.
```diff ```js
define(function () { define(function () {
function BarGraphController($scope, telemetryHandler) { function BarGraphController($scope, telemetryHandler) {
var handle; var handle;
@ -2023,7 +2023,7 @@ For purposes of this tutorial, a simple node server is provided to stand
in place of this existing telemetry system. It generates real-time data in place of this existing telemetry system. It generates real-time data
and exposes it over a WebSocket connection. and exposes it over a WebSocket connection.
```diff ```js
/*global require,process,console*/ /*global require,process,console*/
var CONFIG = { var CONFIG = {
@ -2205,7 +2205,7 @@ used by the server. It uses a custom format and, for purposes of example,
contains three "subsystems" containing a mix of numeric and string-based contains three "subsystems" containing a mix of numeric and string-based
telemetry. telemetry.
```diff ```json
{ {
"name": "Example Spacecraft", "name": "Example Spacecraft",
"identifier": "sc", "identifier": "sc",
@ -2432,7 +2432,7 @@ server. Our first step will be to add a service that will handle interactions
with the server; this will not be used by Open MCT directly, but will be with the server; this will not be used by Open MCT directly, but will be
used by subsequent components we add. used by subsequent components we add.
```diff ```js
/*global define,WebSocket*/ /*global define,WebSocket*/
define( define(
@ -2487,7 +2487,7 @@ subsystems. This means that we need to convert the data from the dictionary
into domain object models, and expose these to Open MCT via a into domain object models, and expose these to Open MCT via a
`modelService`. `modelService`.
```diff ```js
/*global define*/ /*global define*/
define( define(
@ -2621,7 +2621,7 @@ This allows our telemetry dictionary to be expressed as domain object models
fix this, we will need another script which will add these subsystems to the fix this, we will need another script which will add these subsystems to the
root-level object we added in Step 1. root-level object we added in Step 1.
```diff ```js
/*global define*/ /*global define*/
define( define(
@ -2686,7 +2686,7 @@ Finally, we wire in these changes by modifying our plugin's `bundle.js` to
provide metadata about how these pieces interact (both with each other, and provide metadata about how these pieces interact (both with each other, and
with the platform): with the platform):
```diff ```js
define([ define([
'openmct', 'openmct',
+ './src/ExampleTelemetryServerAdapter', + './src/ExampleTelemetryServerAdapter',
@ -2834,7 +2834,7 @@ will do so for the server's historical telemetry.
Our first step will be to add a method to our server adapter which allows us to Our first step will be to add a method to our server adapter which allows us to
send history requests to the server: send history requests to the server:
```diff ```js
/*global define,WebSocket*/ /*global define,WebSocket*/
define( define(
@ -2893,7 +2893,7 @@ identifier, the pending promise is resolved.
This `history` method will be used by a `telemetryService` provider which we This `history` method will be used by a `telemetryService` provider which we
will implement: will implement:
```diff ```js
/*global define*/ /*global define*/
define( define(
@ -2979,7 +2979,7 @@ Finally, note that we also have a `subscribe` method, to satisfy the interface o
This script uses an `ExampleTelemetrySeries` class, which looks like: This script uses an `ExampleTelemetrySeries` class, which looks like:
```diff ```js
/*global define*/ /*global define*/
define( define(
@ -3011,7 +3011,7 @@ it with the interface expected by the platform (the methods shown.)
Finally, we expose this `telemetryService` provider declaratively: Finally, we expose this `telemetryService` provider declaratively:
```diff ```js
define([ define([
'openmct', 'openmct',
'./src/ExampleTelemetryServerAdapter', './src/ExampleTelemetryServerAdapter',
@ -3126,7 +3126,7 @@ Finally, we want to utilize the server's ability to subscribe to telemetry
from Open MCT. To do this, first we want to expose some new methods for from Open MCT. To do this, first we want to expose some new methods for
this from our server adapter: this from our server adapter:
```diff ```js
/*global define,WebSocket*/ /*global define,WebSocket*/
define( define(
@ -3199,7 +3199,7 @@ with these subscriptions.
We then need only to utilize these methods from our `telemetryService`: We then need only to utilize these methods from our `telemetryService`:
```diff ```js
/*global define*/ /*global define*/
define( define(
@ -3305,4 +3305,4 @@ server can handle this.)
Running Open MCT again, we can still plot our historical telemetry - but Running Open MCT again, we can still plot our historical telemetry - but
now we also see that it updates in real-time as more data comes in from the now we also see that it updates in real-time as more data comes in from the
server. server.