<commit_before>/*
 * The aspiredb project
 * 
 * Copyright (c) 2013 University of British Columbia
 * 
 * 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.
 *
 */
Ext
		.require([ 'ASPIREdb.store.SubjectStore',
				'ASPIREdb.view.CreateLabelWindow',
				'ASPIREdb.view.LabelControlWindow',
				'ASPIREdb.TextDataDownloadWindow' ]);

/**
 * Queries Subject values and loads them into a {@link Ext.grid.Panel}
 * 
 */
Ext.define('ASPIREdb.view.SubjectGrid', {
	extend : 'Ext.grid.Panel',
	alias : 'widget.subjectGrid',
	title : 'Subject',
	id : 'subjectGrid',
	multiSelect : true,
	store : Ext.create('ASPIREdb.store.SubjectStore'),
	config : {

		// member variables

		// labels that are displayable
		// { label.id : label.valueObject }
		visibleLabels : {},

		// all the subject value objects in the grid
		valueObjects : [],

		// selected subjects in the grid
		selSubjects : [],
        
        // the current filters used
        filterConfigs : []
	},
	constructor : function(cfg) {
		this.initConfig(cfg);
		this.callParent(arguments);
	},
	columns : [
			{
				text : "Subject Id",
				dataIndex : 'patientId',
				flex : 1
			},
			{
				text : "Labels",
				dataIndex : 'labelIds',
				// This is very slow we need to rethink this
				renderer : function(value) {
					
					var ret = "";
					for ( var i = 0; i < value.length; i++) {
						var label = this.visibleLabels[value[i]];
						if (label == undefined) {
							continue;
						}
						if (label.isShown) {
							var fontcolor = (parseInt(label.colour, 16) > 0xffffff/2) ? 'black' : 'white';	
							ret += "<font color="+fontcolor+"><span style='background-color: "
									+ label.colour + "'>&nbsp&nbsp"+ label.name+"&nbsp</span></font>&nbsp&nbsp&nbsp";
						}
					}
					return ret;
				},
				flex : 1
			},
			{
				text : "# of variants",
				dataIndex : 'varientNos',
				renderer : function(value) {
					return value;
				},
				flex : 1
			},
			{
				text : "# of phenotypes",
				dataIndex : 'phenotypeNos',
				flex : 1
			}],

	/**
	 * Create tool bar and buttons on top of subject grid
	 */
	initComponent : function() {

		this.callParent();

		var me = this;

		this.labelsMenu = Ext.create('Ext.menu.Menu', {
			items : [ {
				itemId : 'makeLabel',
				text : 'Make label...',
				disabled : true,
				handler : this.makeLabelHandler,
				scope : this
			}, {
				itemId : 'labelSettings',
				text : 'Settings...',
				disabled : false,
				handler : this.labelSettingsHandler,
				scope : this
			} ]
		});

		this.labelsButton = Ext.create('Ext.Button', {
			text : '<b>Labels</b>',
			itemId : 'labelsButton',
			menu : this.labelsMenu
		});
		
		this.selectAllButton = Ext.create('Ext.Button', {
			itemId : 'selectAll',
			text : 'Select All',
			handler : this.selectAllHandler,
			scope : this
		});

		this.saveButton = Ext.create('Ext.Button', {
			itemId : 'saveButton',
			text : '',
			tooltip : 'Download table contents as text',
			icon : 'scripts/ASPIREdb/resources/images/icons/disk.png',
		});

		this.toolbar = Ext.create('Ext.toolbar.Toolbar', {
			itemId : 'subjectGridToolbar',
			dock : 'top'
		});

		this.toolbar.add(this.labelsButton);
		this.toolbar.add(this.selectAllButton);
		this.toolbar.add(Ext.create('Ext.toolbar.Fill'));
		this.toolbar.add(this.saveButton);
		this.addDocked(this.toolbar);

		// When Save button is clicked open text data downlaod window
		this.saveButton.on('click', function() {
			ASPIREdb.TextDataDownloadWindow
					.showSubjectDownload(me.valueObjects);
		}, this);
		
		//when subject filter submit
		ASPIREdb.EVENT_BUS.on('filter_submit', this.filterSubmitHandler, this);
		
		//when subject selected
		this.on('selectionchange', me.selectionChangeHandler, me);
		
		//when subject label change
        ASPIREdb.EVENT_BUS.on('label_subject_change', this.refreshGridView, this);
	},

	/**
	 * Load subject labels created by the user
	 * @return visibleLabels
	 */
	createVisibleLabels : function() {
		var visibleLabels = [];
		var suggestionContext = new SuggestionContext();
		suggestionContext.activeProjectIds = ASPIREdb.ActiveProjectSettings.getActiveProjectIds();
		
		// load all labels created by this user
		SubjectService.suggestLabels(suggestionContext, {
			callback : function(labels) {
				for ( var idx in labels) {
					var label = labels[idx];
					visibleLabels[label.id] = label;
				}
			}
		});	
		
		return visibleLabels;
	},
	<commit_msg>Bug 3886 - Remove labels from selected Subjects and Variants<commit_after>/*
 * The aspiredb project
 * 
 * Copyright (c) 2013 University of British Columbia
 * 
 * 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.
 *
 */
Ext
		.require([ 'ASPIREdb.store.SubjectStore',
				'ASPIREdb.view.CreateLabelWindow',
				'ASPIREdb.view.LabelControlWindow',
				'ASPIREdb.TextDataDownloadWindow' ]);

/**
 * Queries Subject values and loads them into a {@link Ext.grid.Panel}
 * 
 */
Ext.define('ASPIREdb.view.SubjectGrid', {
	extend : 'Ext.grid.Panel',
	alias : 'widget.subjectGrid',
	title : 'Subject',
	id : 'subjectGrid',
	multiSelect : true,
	store : Ext.create('ASPIREdb.store.SubjectStore'),
	config : {

		// member variables

		// labels that are displayable
		// { label.id : label.valueObject }
		visibleLabels : {},

		// all the subject value objects in the grid
		valueObjects : [],

		// selected subjects in the grid
		selSubjects : [],
        
        // the current filters used
        filterConfigs : []
	},
	constructor : function(cfg) {
		this.initConfig(cfg);
		this.callParent(arguments);
	},
	columns : [
			{
				text : "Subject Id",
				dataIndex : 'patientId',
				flex : 1
			},
			{
				text : "Labels",
				dataIndex : 'labelIds',
				// This is very slow we need to rethink this
				renderer : function(value) {
					
					var ret = "";
					for ( var i = 0; i < value.length; i++) {
						var label = this.visibleLabels[value[i]];
						if (label == undefined) {
							continue;
						}
						if (label.isShown) {
							var fontcolor = (parseInt(label.colour, 16) > 0xffffff/2) ? 'black' : 'white';	
							ret += "<font color="+fontcolor+"><span style='background-color: "
									+ label.colour + "'>&nbsp&nbsp"+ label.name+"&nbsp</span></font>&nbsp&nbsp&nbsp";
						}
					}
					return ret;
				},
				flex : 1
			},
			{
				text : "# of variants",
				dataIndex : 'varientNos',
				renderer : function(value) {
					return value;
				},
				flex : 1
			},
			{
				text : "# of phenotypes",
				dataIndex : 'phenotypeNos',
				flex : 1
			}],

	/**
	 * Create tool bar and buttons on top of subject grid
	 */
	initComponent : function() {

		this.callParent();

		var me = this;

		this.labelsMenu = Ext.create('Ext.menu.Menu', {
			items : [ {
				itemId : 'makeLabel',
				text : 'Make label...',
				disabled : true,
				handler : this.makeLabelHandler,
				scope : this
			}, {
				itemId : 'labelSettings',
				text : 'Settings...',
				disabled : false,
				handler : this.labelSettingsHandler,
				scope : this
			} ]
		});

		this.labelsButton = Ext.create('Ext.Button', {
			text : '<b>Labels</b>',
			itemId : 'labelsButton',
			menu : this.labelsMenu
		});
		
		this.selectAllButton = Ext.create('Ext.Button', {
			itemId : 'selectAll',
			text : 'Select All',
			handler : this.selectAllHandler,
			scope : this
		});

		this.saveButton = Ext.create('Ext.Button', {
			itemId : 'saveButton',
			text : '',
			tooltip : 'Download table contents as text',
			icon : 'scripts/ASPIREdb/resources/images/icons/disk.png',
		});

		this.toolbar = Ext.create('Ext.toolbar.Toolbar', {
			itemId : 'subjectGridToolbar',
			dock : 'top'
		});

		this.toolbar.add(this.labelsButton);
		this.toolbar.add(this.selectAllButton);
		this.toolbar.add(Ext.create('Ext.toolbar.Fill'));
		this.toolbar.add(this.saveButton);
		this.addDocked(this.toolbar);

		// When Save button is clicked open text data downlaod window
		this.saveButton.on('click', function() {
			ASPIREdb.TextDataDownloadWindow
					.showSubjectDownload(me.valueObjects);
		}, this);
		
		//when subject filter submit
		ASPIREdb.EVENT_BUS.on('filter_submit', this.filterSubmitHandler, this);
		
		//when subject selected
		this.on('selectionchange', me.selectionChangeHandler, me);
		
		//when subject label change
        ASPIREdb.EVENT_BUS.on('subject_Label_changed', this.refreshGridView, this);
	},

	/**
	 * Load subject labels created by the user
	 * @return visibleLabels
	 */
	createVisibleLabels : function() {
		var visibleLabels = [];
		var suggestionContext = new SuggestionContext();
		suggestionContext.activeProjectIds = ASPIREdb.ActiveProjectSettings.getActiveProjectIds();
		
		// load all labels created by this user
		SubjectService.suggestLabels(suggestionContext, {
			callback : function(labels) {
				for ( var idx in labels) {
					var label = labels[idx];
					visibleLabels[label.id] = label;
				}
			}
		});	
		
		return visibleLabels;
	},
	
{'fraction_non_alphanumeric': 0.13334007278608978, 'fraction_numerical': 0.003841488071168621, 'mean_word_length': 2.965130260521042, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '935722', 'n_tokens_mistral': 3697, 'n_tokens_neox': 3008, 'n_words': 784}