<commit_before>﻿/*
  Aras.ViewModel provides a .NET library for building Aras Innovator Applications

  Copyright (C) 2015 Processwall Limited.

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU Affero General Public License as published
  by the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU Affero General Public License for more details.

  You should have received a copy of the GNU Affero General Public License
  along with this program.  If not, see http://opensource.org/licenses/AGPL-3.0.
 
  Company: Processwall Limited
  Address: The Winnowing House, Mill Lane, Askham Richard, York, YO23 3NW, United Kingdom
  Tel:     +44 113 815 3440
  Email:   <EMAIL>
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Aras.ViewModel
{
    [Attributes.ClientControl("Aras.View.Grid")]
    public class Grid : Control
    {
        [ViewModel.Attributes.Property("Select", Aras.ViewModel.Attributes.PropertyTypes.Command, true)]
        [ViewModel.Attributes.Command("Select")]
        public SelectCommand Select { get; private set; }

        [ViewModel.Attributes.Property("Columns", Aras.ViewModel.Attributes.PropertyTypes.ControlList, true)]
        public Model.ObservableList<Column> Columns { get; private set; }

        [ViewModel.Attributes.Property("Rows", Aras.ViewModel.Attributes.PropertyTypes.ControlList, true)]
        public Model.ObservableList<Row> Rows { get; private set; }

        public Model.ObservableList<Row> SelectedRows { get; private set; }

        public Column AddColumn(String Name, String Label, Int32 Width)
        {
            Column col = new Column(this, Name, Label, Width);
            this.Columns.Add(col);
            return col;
        }

        private Boolean _allowSelect;
        public Boolean AllowSelect
        {
            get
            {
                return this._allowSelect;
            }
            set
            {
                this._allowSelect = value;
                this.Select.UpdateCanExecute(value);
            }
        }

        private List<Row> RowCache;

        private Row AddRow()
        {
            if (this.RowCache.Count() > this.Rows.Count())
            {
                // Use Row from Cache
                Row row = this.RowCache[this.Rows.Count()];
                this.Rows.Add(row);
                
                // Queue Cached Row
                this.Session.QueueControl(row);

                return row;
            }
            else
            {
                // Create new Row<commit_msg>Queue Grid Cells when using a Cached Row<commit_after>﻿/*
  Aras.ViewModel provides a .NET library for building Aras Innovator Applications

  Copyright (C) 2015 Processwall Limited.

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU Affero General Public License as published
  by the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU Affero General Public License for more details.

  You should have received a copy of the GNU Affero General Public License
  along with this program.  If not, see http://opensource.org/licenses/AGPL-3.0.
 
  Company: Processwall Limited
  Address: The Winnowing House, Mill Lane, Askham Richard, York, YO23 3NW, United Kingdom
  Tel:     +44 113 815 3440
  Email:   <EMAIL>
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Aras.ViewModel
{
    [Attributes.ClientControl("Aras.View.Grid")]
    public class Grid : Control
    {
        [ViewModel.Attributes.Property("Select", Aras.ViewModel.Attributes.PropertyTypes.Command, true)]
        [ViewModel.Attributes.Command("Select")]
        public SelectCommand Select { get; private set; }

        [ViewModel.Attributes.Property("Columns", Aras.ViewModel.Attributes.PropertyTypes.ControlList, true)]
        public Model.ObservableList<Column> Columns { get; private set; }

        [ViewModel.Attributes.Property("Rows", Aras.ViewModel.Attributes.PropertyTypes.ControlList, true)]
        public Model.ObservableList<Row> Rows { get; private set; }

        public Model.ObservableList<Row> SelectedRows { get; private set; }

        public Column AddColumn(String Name, String Label, Int32 Width)
        {
            Column col = new Column(this, Name, Label, Width);
            this.Columns.Add(col);
            return col;
        }

        private Boolean _allowSelect;
        public Boolean AllowSelect
        {
            get
            {
                return this._allowSelect;
            }
            set
            {
                this._allowSelect = value;
                this.Select.UpdateCanExecute(value);
            }
        }

        private List<Row> RowCache;

        private Row AddRow()
        {
            if (this.RowCache.Count() > this.Rows.Count())
            {
                // Use Row from Cache
                Row row = this.RowCache[this.Rows.Count()];
                this.Rows.Add(row);
                
                // Queue Cached Row
                this.Session.QueueControl(row);

                foreach(Cell cell in row.Cells)
                {
                    this.Session.QueueControl(cell);
                }

                return row;
            }
            else
            {
                // Create new Row
{'fraction_non_alphanumeric': 0.07809619574325456, 'fraction_numerical': 0.008044243338360985, 'mean_word_length': 2.1262441068622318, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5486293', 'n_tokens_mistral': 1586, 'n_tokens_neox': 1476, 'n_words': 511}