<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.
 */
CLASS({
  package: 'foam.tutorials.todo',
  name: 'TodoApp',
  extendsModel: 'foam.ui.DetailView',
  requires: [
    'foam.dao.EasyDAO',
    'foam.mlang.CannedQuery',
    'foam.tutorials.todo.Controller',
    'foam.tutorials.todo.model.Todo',
    'foam.tutorials.todo.ui.TodoCitationView',
    'foam.ui.TextFieldView',
  ],

  exports: [
    'dao',
    'dao as todoDAO',
    'selection',
    'stack',
  ],
  properties: [
    {
      name: 'cannedQueryDAO',
      factory: function() {
        return [
          this.CannedQuery.create({
            label: 'Todo',
            expression: AND(
                EQ(this.Todo.COMPLETED, false),
                NOT(this.Todo.PARENT))
          }),
          this.CannedQuery.create({
            label: 'Completed',
            expression: AND(
                EQ(this.Todo.COMPLETED, true),
                NOT(this.Todo.PARENT))
          }),
          this.CannedQuery.create({
            label: 'Everything',
            expression: NOT(this.Todo.PARENT)
          })
        ].dao;
      }
    },
    {
      name: 'dao',
      factory: function() {
        return this.EasyDAO.create({
          model: this.Todo,
          daoType: 'LOCAL',
          seqNo: true
        });
      }
    },
    {
      name: 'data',
      factory: function() {
        return this.Controller.create({
          dao: this.dao,
          cannedQueryDAO: this.cannedQueryDAO,
        });
      }
    },
    {
      name: 'newTodo',
      view: {
        factory_: 'foam.ui.TextFieldView',
        placeholder: 'Create new todo',
      },
      postSet: function(old, nu) {
        nu = nu ? nu.trim() : '';
        if ( ! nu ) return;
        this.dao.put(this.Todo.create({ description: nu }));
        this.newTodo = '';
      },
    },
    {
      name: 'className',
      defaultValue: 'todo-app'
    },
  ],

  templates: [
    function CSS() {/*
      .todo-app {
      }
      .menu {
        background: #e9e9e9;
      }
      .menu div {
        padding: 8px 12px;
      }
      .search {
        margin: 8px;
      }
      .search input {
        padding: 6px;
      }
      .new-todo {
        margin: 8px;
      }
      .new-todo input {
        padding: 6px;
      }

      .todo-list {
        margin-top: 8px;
      }<commit_msg>TodoApp: Use popups to edit todo items<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.
 */
CLASS({
  package: 'foam.tutorials.todo',
  name: 'TodoApp',
  extendsModel: 'foam.ui.DetailView',
  requires: [
    'foam.dao.EasyDAO',
    'foam.mlang.CannedQuery',
    'foam.tutorials.todo.Controller',
    'foam.tutorials.todo.model.Todo',
    'foam.tutorials.todo.ui.TodoCitationView',
    'foam.tutorials.todo.ui.TodoDetailView',
    'foam.ui.TextFieldView',
    'foam.ui.md.PopupView',
  ],

  exports: [
    'dao',
    'dao as todoDAO',
    'selection$',
  ],
  properties: [
    {
      name: 'cannedQueryDAO',
      factory: function() {
        return [
          this.CannedQuery.create({
            label: 'Todo',
            expression: AND(
                EQ(this.Todo.COMPLETED, false),
                NOT(this.Todo.PARENT))
          }),
          this.CannedQuery.create({
            label: 'Completed',
            expression: AND(
                EQ(this.Todo.COMPLETED, true),
                NOT(this.Todo.PARENT))
          }),
          this.CannedQuery.create({
            label: 'Everything',
            expression: NOT(this.Todo.PARENT)
          })
        ].dao;
      }
    },
    {
      name: 'dao',
      factory: function() {
        return this.EasyDAO.create({
          model: this.Todo,
          daoType: 'LOCAL',
          seqNo: true
        });
      }
    },
    {
      name: 'data',
      factory: function() {
        return this.Controller.create({
          dao: this.dao,
          cannedQueryDAO: this.cannedQueryDAO,
        });
      }
    },
    {
      name: 'newTodo',
      view: {
        factory_: 'foam.ui.TextFieldView',
        placeholder: 'Create new todo',
      },
      postSet: function(old, nu) {
        nu = nu ? nu.trim() : '';
        if ( ! nu ) return;
        this.dao.put(this.Todo.create({ description: nu }));
        this.newTodo = '';
      },
    },
    {
      name: 'className',
      defaultValue: 'todo-app'
    },
    {
      name: 'overlay',
      factory: function() {
        var view = this.PopupView.create({
          delegate: 'foam.tutorials.todo.ui.TodoDetailView',
        });
        view.state$.addListener(function(_, prop, old, nu) {
          if (nu !== 'open') {
            this.selection = '';
          }
        }.bind(this));
        return view;
      }
    },
    {
      name: 'selection',
      documentation: 'Holds the currently selected todo item.',
      postSet: function(old, nu) {
        if (nu) {
          // Open the overlay with this item.
          this.overlay.data = nu;
          this.overlay.open();
        }
      }
    },
  ],

  templates: [
    function CSS() {/*
      .todo-app {
      }
      .menu {
        background: #e9e9e9;
      }
      .menu div {
        padding: 8px 12px;
      }
      .search {
        margin: 8px;
      }
      .search input {
        padding: 6px;
      }
      .new-todo {
        margin: 8px;
      }
      .new-todo input {
        padding: 6px;
      }

      .todo-list {
        margin-top: 8px;
      }
{'fraction_non_alphanumeric': 0.13040838014270534, 'fraction_numerical': 0.005768938818885684, 'mean_word_length': 1.6780487804878048, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1764496', 'n_tokens_mistral': 2132, 'n_tokens_neox': 2079, 'n_words': 476}