<commit_before>Ext.define('CustomApp', {
    extend: 'Rally.app.App',
    componentCls: 'app',

    items: [
        {
            xtype: 'container',
            itemId: 'preferenceNameContainer',
            padding: '10',
            layout: {
                type: 'vbox'
            },
            flex: 1
        },
        {
            xtype: 'container',
            itemId: 'filterValueContainer',
            padding: '10'
        }
    ],

    _workspaceObjectID: null,
    _workspaceRef: null,

    _typeFeature: null,
    _typeInitiative: null,

    _filterNameTextbox: null,
    _findPreferenceButton: null,
    _deletePreferenceButton: null,

    _preferencesStore: null,
    _foundPrefRecord: null,

    launch: function() {
        var me = this;
        var currentContext = Rally.environment.getContext();

        //Get the current user and workspace
        me._user = currentContext.getUser();
        me._workspaceObjectID = currentContext.getWorkspace().ObjectID;
        me._workspaceRef = "/workspace/" + me._workspaceObjectID;

        // console.log(me._workspaceObjectID);

        this._buildUI(this);
    },

    _buildUI: function(me) {

        me._filterNameTextbox = Ext.create('Rally.ui.TextField', {
            fieldLabel: 'Preference Name:',
            width: 400
        });
        me.down('#preferenceNameContainer').add(me._filterNameTextbox);

        me._findPreferenceButton = Ext.create('Rally.ui.Button', {
            text: "Find Preference",
            handler: function() {
                me._queryFilterPref();
            }
        });
        me.down('#preferenceNameContainer').add(me._findPreferenceButton);
    },

    _queryFilterPref: function() {

        var me = this;
        me._filterSearchString = me._filterNameTextbox.getValue();

        me._preferencesStore = Ext.create('Rally.data.wsapi.Store', {
            model: 'Preference',
            autoLoad: true,
            fetch: true,
            listeners: {
                scope: this,
                load: me._preferenceStoreLoaded
            },
            filters: [
                {
                    property: 'Name',
                    operator: '=',
                    value: me._filterSearchString
                }
            ]
        });
    },

    _deletePreference: function(preferenceModel, scope) {

        var me = scope;
        preferenceModel.destroy({
            callback: function(result, operation) {
                if(operation.wasSuccessful()) {

                    // Notify of successful deletion
                    Ext.create('Rally.ui.dialog.ConfirmDialog', {
                        title: "Preference Deleted",
                        message: "Preference Successfully Removed!",
                        confirmLabel: "Ok"
                    });
                } else {
                    Ext.create('Rally.ui.dialog.ConfirmDialog', {
                        title: "Preference Not Removed",
                        message: "Error Deleting Preference!",
                        confirmLabel: "Ok",
                        listeners: {
                            confirm: function () {
                                return;
                            }
                        }
                    });
                }
            }
        });

    },

    _deletePreferenceHandler: function(record, scope) {

        var me = scope;

        var recordObjectID = record.get('ObjectID');

        var preferenceModel = Rally.data.ModelFactory.getModel({
            type: 'Preference',
            scope: this,
            success: function(model, operation) {
                model.load(recordObjectID, {
                    scope: this,
                    success: function(model, operation) {

                        var confirmLabel = "Delete Preference Permanently";
                        var message = "Really Delete Preference?";

                        Ext.create('Rally.ui.dialog.ConfirmDialog', {
                            message: message,
                            confirmLabel: confirmLabel,
                            listeners: {
                                confirm: function(){
                                    me._deletePreference(model, me);
                                }
                            }
                        });
                    }
                });
            }
        });

    },

    _preferenceStoreLoaded: function(store, records) {

        var me = this;

        console.log(records.length);

        if (records.length === 0) {
            Ext.Msg.alert('Preference Not Found', me._filterSearchString);
        }
;
        Ext.Array.each(records, function(record) {

            var prefWorkspace = record.get('Workspace');
            var prefWorkspaceRef = prefWorkspace._ref;

            if (prefWorkspaceRef === me._workspaceRef) {
                me._foundPrefRecord = record;
                me._filterValue = record.get('Value');
                var preferenceName = record.get('Name');
                Ext.Msg.alert('Preference Found: ' + preferenceName, me._filterValue);
                // console.log(me._foundPrefRecord);<commit_msg>Added dialog warning when pref not found<commit_after>Ext.define('CustomApp', {
    extend: 'Rally.app.App',
    componentCls: 'app',

    items: [
        {
            xtype: 'container',
            itemId: 'preferenceNameContainer',
            padding: '10',
            layout: {
                type: 'vbox'
            },
            flex: 1
        },
        {
            xtype: 'container',
            itemId: 'filterValueContainer',
            padding: '10'
        }
    ],

    _workspaceObjectID: null,
    _workspaceRef: null,

    _typeFeature: null,
    _typeInitiative: null,

    _filterNameTextbox: null,
    _findPreferenceButton: null,
    _deletePreferenceButton: null,

    _preferencesStore: null,
    _foundPrefRecord: null,

    launch: function() {
        var me = this;
        var currentContext = Rally.environment.getContext();

        //Get the current user and workspace
        me._user = currentContext.getUser();
        me._workspaceObjectID = currentContext.getWorkspace().ObjectID;
        me._workspaceRef = "/workspace/" + me._workspaceObjectID;

        // console.log(me._workspaceObjectID);

        this._buildUI(this);
    },

    _buildUI: function(me) {

        me._filterNameTextbox = Ext.create('Rally.ui.TextField', {
            fieldLabel: 'Preference Name:',
            width: 400
        });
        me.down('#preferenceNameContainer').add(me._filterNameTextbox);

        me._findPreferenceButton = Ext.create('Rally.ui.Button', {
            text: "Find Preference",
            handler: function() {
                me._queryFilterPref();
            }
        });
        me.down('#preferenceNameContainer').add(me._findPreferenceButton);
    },

    _queryFilterPref: function() {

        var me = this;
        me._filterSearchString = me._filterNameTextbox.getValue();

        me._preferencesStore = Ext.create('Rally.data.wsapi.Store', {
            model: 'Preference',
            autoLoad: true,
            fetch: true,
            listeners: {
                scope: this,
                load: me._preferenceStoreLoaded
            },
            filters: [
                {
                    property: 'Name',
                    operator: '=',
                    value: me._filterSearchString
                }
            ]
        });
    },

    _deletePreference: function(preferenceModel, scope) {

        var me = scope;
        preferenceModel.destroy({
            callback: function(result, operation) {
                if(operation.wasSuccessful()) {

                    // Notify of successful deletion
                    Ext.create('Rally.ui.dialog.ConfirmDialog', {
                        title: "Preference Deleted",
                        message: "Preference Successfully Removed!",
                        confirmLabel: "Ok"
                    });
                } else {
                    Ext.create('Rally.ui.dialog.ConfirmDialog', {
                        title: "Preference Not Removed",
                        message: "Error Deleting Preference!",
                        confirmLabel: "Ok",
                        listeners: {
                            confirm: function () {
                                return;
                            }
                        }
                    });
                }
            }
        });

    },

    _deletePreferenceHandler: function(record, scope) {

        var me = scope;

        var recordObjectID = record.get('ObjectID');

        var preferenceModel = Rally.data.ModelFactory.getModel({
            type: 'Preference',
            scope: this,
            success: function(model, operation) {
                model.load(recordObjectID, {
                    scope: this,
                    success: function(model, operation) {

                        var confirmLabel = "Delete Preference Permanently";
                        var message = "Really Delete Preference?";

                        Ext.create('Rally.ui.dialog.ConfirmDialog', {
                            message: message,
                            confirmLabel: confirmLabel,
                            listeners: {
                                confirm: function(){
                                    me._deletePreference(model, me);
                                }
                            }
                        });
                    }
                });
            }
        });

    },

    _preferenceStoreLoaded: function(store, records) {

        var me = this;
        
        if (records.length === 0) {
            Ext.Msg.alert('Preference Not Found', me._filterSearchString);
        }
;
        Ext.Array.each(records, function(record) {

            var prefWorkspace = record.get('Workspace');
            var prefWorkspaceRef = prefWorkspace._ref;

            if (prefWorkspaceRef === me._workspaceRef) {
                me._foundPrefRecord = record;
                me._filterValue = record.get('Value');
                var preferenceName = record.get('Name');
                Ext.Msg.alert('Preference Found: ' + preferenceName, me._filterValue);
                // console.log(me._foundPrefRecord);
{'fraction_non_alphanumeric': 0.10149110149110149, 'fraction_numerical': 0.0017316017316017316, 'mean_word_length': 1.3035674717482828, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3409923', 'n_tokens_mistral': 2621, 'n_tokens_neox': 2483, 'n_words': 468}