<commit_before>//using mongoose to generate unique IDs for our schemas..
var mongoose = require('mongoose');

app.factory('SchemaFactory', function($http, $rootScope, Storage) {
    
    // Storage.set('schemas',[]);

    var Schema = function(name, id, fields){
        this.name = name || "";
        this.id = id ||  mongoose.Types.ObjectId().toString();
        this.fields = fields || [];
    }

    Schema.prototype.addField = function(field){
        // if(this.fields.indexOf(field) === -1){
        //     console.log('not here')
        // }
        this.fields.push(new Field(field.name,field.type,field.options));
        Storage.set('schemas', schemas);
    }

    //  Schema.prototype.editField = function(field){
    //     this.fields.push(new Field(field.name,field.type,field.options));
    //     Storage.set('schemas', schemas);
    // }


    Schema.prototype.deleteField = function(field){
        this.fields.splice(this.fields.indexOf(field), 1);
        Storage.set('schemas', schemas);
        $rootScope.$broadcast('newField', this.schemaId);
    }    

    var Field = function(name, type, options){
        this.name = name || "";
        this.type = type || String; //should we use the actual type or a string e.g. Number vs "Number"
        this.options = options || {select: true};
    }

    var convertPojoToSchema = function(sObj){
        return new Schema(sObj.name, sObj.id, sObj.fields.map(f => new Field(f.name, f.type, f.options)))
    }

    var schemas = Storage.get('schemas').map(sObj => convertPojoToSchema(sObj) ) || []; //root data structure

    return {
        Schema: Schema,
        Field: Field,
        getSchemas: function() {
            return schemas;
        },
        addSchema: function(name){<commit_msg>can now edit fields as well<commit_after>//using mongoose to generate unique IDs for our schemas..
var mongoose = require('mongoose');

app.factory('SchemaFactory', function($http, $rootScope, Storage) {
    
    // Storage.set('schemas',[]);

    var Schema = function(name, id, fields){
        this.name = name || "";
        this.id = id ||  mongoose.Types.ObjectId().toString();
        this.fields = fields || [];
    }

    Schema.prototype.addField = function(field){
        if(this.fields.indexOf(field) !== -1){
            this.fields[this.fields.indexOf(field)] = field;
        }else{
            this.fields.push(new Field(field.name,field.type,field.options));
            Storage.set('schemas', schemas);
        }
    }



    Schema.prototype.deleteField = function(field){
        this.fields.splice(this.fields.indexOf(field), 1);
        Storage.set('schemas', schemas);
        $rootScope.$broadcast('newField', this.schemaId);
    }    

    var Field = function(name, type, options){
        this.name = name || "";
        this.type = type || String; //should we use the actual type or a string e.g. Number vs "Number"
        this.options = options || {select: true};
    }

    var convertPojoToSchema = function(sObj){
        return new Schema(sObj.name, sObj.id, sObj.fields.map(f => new Field(f.name, f.type, f.options)))
    }

    var schemas = Storage.get('schemas').map(sObj => convertPojoToSchema(sObj) ) || []; //root data structure

    return {
        Schema: Schema,
        Field: Field,
        getSchemas: function() {
            return schemas;
        },
        addSchema: function(name){
{'fraction_non_alphanumeric': 0.1538913362701909, 'fraction_numerical': 0.0011747430249632893, 'mean_word_length': 2.4969199178644765, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '5430368', 'n_tokens_mistral': 1029, 'n_tokens_neox': 1005, 'n_words': 219}