<commit_before>/**
 * @license
 * Copyright 2015 Google Inc. 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.
 */

MODEL({
  package: 'foam.demos.sevenguis',
  name: 'Timer',
  properties: [
    {
      name: 'elapsedTime',
      defaultValue: 0
    },
    {
      name: 'duration',
      units: 'ms',
      view: 'foam.ui.RangeView',
      defaultValue: 5000,
    },
    {
      name: 'progress',
      view: 'foam.ui.ProgressView',
//      mode: 'read-only'
    },
    {
      name: 'lastTick_',
      hidden: true,
      defaultValue: 0
    }
  ],
  methods: [
    function init() {
      this.SUPER();
      this.X.dynamic(function() {
        this.progress = 100 * Math.min(1, this.elapsedTime / this.duration);
      }.bind(this));
      this.tick();
    }
  ],
  actions: [
    {
      name: 'reset',
      action: function() {
        this.elapsedTime = this.lastTick_ = 0;
        this.tick();
      }
    }
  ],
  templates: [
    function toDetailHTML() {/*
      Elapsed Time: $$progress <br>
      $$elapsedTime{model_: 'foam.ui.TextFieldView', mode: 'read-only'} <br>
      Duration: $$duration <br>
    */}
  ],
  listeners: [
    {
      name: 'tick',
      isFramed: true,
      code: function() {
        if ( this.elapsedTime >= this.duration ) return;
        var now = Date.now();
        if ( this.lastTick_ ) this.elapsedTime += now - this.lastTick_;
        this.elapsedTime = Math.min(this.duration, this.elapsedTime);
        this.lastTick_ = now;
        this.tick();
      }
    }
  ]
});<commit_msg>Finished Timer demo.<commit_after>/**
 * @license
 * Copyright 2015 Google Inc. 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.
 */

MODEL({
  package: 'foam.demos.sevenguis',
  name: 'Timer',
  extendsModel: 'foam.ui.View',
  properties: [
    {
      name: 'progress',
      label: 'Elapsed Time',
      view: 'foam.ui.ProgressView',
//      mode: 'read-only'
    },
    {
      name: 'elapsedTime',
      label: '',
      mode: 'read-only',
      defaultValue: 0
    },
    {
      name: 'duration',
      units: 'ms',
      view: { factory_: 'foam.ui.RangeView', maxValue: 10000 },
      defaultValue: 5000
    },
    {
      name: 'lastTick_',
      hidden: true,
      defaultValue: 0
    }
  ],
  methods: [
    function init() {
      this.SUPER();
      this.X.dynamic(function() {
        this.progress = 100 * Math.min(1, 1000 * this.elapsedTime / this.duration);
      }.bind(this));
      this.tick();
      this.duration$.addListener(this.tick);
    }
  ],
  actions: [
    {
      name: 'reset',
      action: function() {
        this.elapsedTime = this.lastTick_ = 0;
        this.tick();
      }
    }
  ],
  templates: [
    function CSS() {/*
      body { padding: 10px !important; font-size: 18px !important; }
      .elapsed { margin-top: 10px; }
      .label { display: inline-block; width: 130px; }
      row { display: block; height: 30px; }
      input[name="duration"] { width: 182px; }
      input { margin-left: 12px; }
      button { width: 332px !important; margin-top: 16px !important; }
    */},
    function toHTML() {/*
      <row><span class="label">Elapsed Time:</span> $$progress</row>
      <row class="elapsed">$$elapsedTime{model_: 'foam.ui.FloatFieldView', precision: 1, mode: 'read-only'}s</row>
      <row><span class="label">Duration:</span> $$duration{onKeyMode: true}</row>
      $$reset
    */}
  ],
  listeners: [
    {
      name: 'tick',
      isFramed: true,
      code: function() {
        if ( 1000 * this.elapsedTime >= this.duration ) return;
        var now = Date.now();
        if ( this.lastTick_ ) this.elapsedTime += (now - this.lastTick_)/1000;
        this.elapsedTime = Math.min(this.duration/1000, this.elapsedTime);
        this.lastTick_ = now;
        this.tick();
      }
    }
  ]
});
{'fraction_non_alphanumeric': 0.1417956656346749, 'fraction_numerical': 0.01671826625386997, 'mean_word_length': 2.35595567867036, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7535578', 'n_tokens_mistral': 1591, 'n_tokens_neox': 1513, 'n_words': 411}