<commit_before>/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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.
 */
// dojo.provide allows pages use all types declared in this resource
dojo.provide("demo.LayoutManager");
dojo.require("dijit.form.Button");
dojo.require("dijit.form.ComboBox");
dojo.require("dojo.data.ItemFileWriteStore");

//LayoutManager
// looks after the loading & saving of arrangements of bundles on the surface.
// stores configurations by name, by provider.
//
// listens for provider change notifications to know what the current provider is,
// when a provider is selected, all current layouts are discarded, and the layout
// set for the new provider is setup.
//
// the list of layouts for a provider is stored in a cookie as 
//    "ozzy.demo.ui.layouts.<providerName>"
// the layout data for each layout is stored in a cookie as 
//    "ozzy.demo.ui.coords.<providerName>.<layoutName>"
//
// both are stored as a json encoded array.
//
// if a provider is selected that we havent seen before, a new cookie is created
// with a layout entry of 'default'.
//
// coord save load is now based over bundle name & version, not id.
// load will only move bundles it is able to match, 
// if a provider gives back different bundles to the ones saved with coords, the
// mismatches are ignored.
//
// TODO:
//   - delete Layout.
//   - (possible) remove load button & trigger off of selection of dropdown.
//   - writeProtect 'default' so it is always the one seen 1st time.
//   - activate loadCoords after provider change.
//   - store 'active' layout to reload on switching to provider
//   - allow dynamic contributions to layout from layout plugins
//     these would add fixed entries to the layout dropdown, and would
//     arrange the layout according to logic rather than a saved layout.
//     these could live server side, or client side, and be added via ajax.
dojo.declare("demo.LayoutManager", [], {
	loadButton:null,
	saveButton:null,
	switchButton:null,
	layoutSelector:null,
	disabled:true,
	items:[],
	layouts:null,
	
	constructor : function(where) {
	  var _this=this;
	  this.loadButton = new dijit.form.Button( 
			  {label: "Load Coords", onClick: function(){_this.loadCoords();} });
	  this.saveButton = new dijit.form.Button( 
			  {label: "Save Coords", onClick: function(){_this.saveCoords();} });
	  
	  this.switchButton = new dijit.form.Button( 
			  {label: "Show/Hide", onClick: function(){_this.switchVisibility();} });  
	  
      this.layouts = new dojo.data.ItemFileWriteStore( {data : {identifier: 'name', items: this.items }});
      
	  this.layoutSelector = new dijit.form.ComboBox( {id: "BundleLayoutSelector",  store: this.layouts} );
	  
	  this.layoutSelector.attr('value',"default");
	    
	  dojo.byId(where).appendChild(this.layoutSelector.domNode);
	  dojo.byId(where).appendChild(this.loadButton.domNode);
	  dojo.byId(where).appendChild(this.saveButton.domNode);
	  dojo.byId(where).appendChild(this.switchButton.domNode);
	  	  
	  this.disable();
	  
	  dojo.subscribe("demo.provider.change", this, this.onProviderChange);
	},
	switchVisibility: function() {
		console.log("Switching visibility");
		dojo.forEach(bundles, function(bundle){
			if(bundle!=null){
				bundle.toggleHidden();
			}
	    });
	},
	onProviderChange: function(evt){
		  console.log("OnProviderChange");
		  console.log(evt);
		  this.enable();
		  
		  this.removeAllLayoutsFromMenu();
			
		  console.log("Adding default if missing");
		  this.addDefaultLayoutIfMissing(providerSelector.getProvider());	 	  
		  this.getLayoutsForProvider(providerSelector.getProvider());
		  
		  this.layoutSelector.attr('value',"default");
	},
	removeAllLayoutsFromMenu: function(){
		  this.layoutSelector.attr('value',"");
		  var _this=this;
			function deleteItems(items, request){
				console.log("total removal query");
				console.log(items);
				console.log(request);			
				dojo.forEach(items, function(item){
					console.log("deleting "+item.name);
					_this.layouts.deleteItem(item);
				});		
			    console.log("end process");
			}
			this.layouts.fetch({query:{}, onComplete: deleteItems});
			this.layouts.save();<commit_msg>ARIES-314 Make showAll and hideAll separate buttons<commit_after>/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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.
 */
// dojo.provide allows pages use all types declared in this resource
dojo.provide("demo.LayoutManager");
dojo.require("dijit.form.Button");
dojo.require("dijit.form.ComboBox");
dojo.require("dojo.data.ItemFileWriteStore");

//LayoutManager
// looks after the loading & saving of arrangements of bundles on the surface.
// stores configurations by name, by provider.
//
// listens for provider change notifications to know what the current provider is,
// when a provider is selected, all current layouts are discarded, and the layout
// set for the new provider is setup.
//
// the list of layouts for a provider is stored in a cookie as 
//    "ozzy.demo.ui.layouts.<providerName>"
// the layout data for each layout is stored in a cookie as 
//    "ozzy.demo.ui.coords.<providerName>.<layoutName>"
//
// both are stored as a json encoded array.
//
// if a provider is selected that we havent seen before, a new cookie is created
// with a layout entry of 'default'.
//
// coord save load is now based over bundle name & version, not id.
// load will only move bundles it is able to match, 
// if a provider gives back different bundles to the ones saved with coords, the
// mismatches are ignored.
//
// TODO:
//   - delete Layout.
//   - (possible) remove load button & trigger off of selection of dropdown.
//   - writeProtect 'default' so it is always the one seen 1st time.
//   - activate loadCoords after provider change.
//   - store 'active' layout to reload on switching to provider
//   - allow dynamic contributions to layout from layout plugins
//     these would add fixed entries to the layout dropdown, and would
//     arrange the layout according to logic rather than a saved layout.
//     these could live server side, or client side, and be added via ajax.
dojo.declare("demo.LayoutManager", [], {
	loadButton:null,
	saveButton:null,
	switchButton:null,
	layoutSelector:null,
	disabled:true,
	items:[],
	layouts:null,
	
	constructor : function(where) {
	  var _this=this;
	  this.loadButton = new dijit.form.Button( 
			  {label: "Load Coords", onClick: function(){_this.loadCoords();} });
	  this.saveButton = new dijit.form.Button( 
			  {label: "Save Coords", onClick: function(){_this.saveCoords();} });
	  
	  this.hideButton = new dijit.form.Button( 
			  {label: "Hide All", onClick: function(){_this.hideAll();} });  
	  
	  this.showButton = new dijit.form.Button( 
			  {label: "Show All", onClick: function(){_this.showAll();} });  
	  
      this.layouts = new dojo.data.ItemFileWriteStore( {data : {identifier: 'name', items: this.items }});
      
	  this.layoutSelector = new dijit.form.ComboBox( {id: "BundleLayoutSelector",  store: this.layouts} );
	  
	  this.layoutSelector.attr('value',"default");
	    
	  dojo.byId(where).appendChild(this.layoutSelector.domNode);
	  dojo.byId(where).appendChild(this.loadButton.domNode);
	  dojo.byId(where).appendChild(this.saveButton.domNode);
	  dojo.byId(where).appendChild(this.hideButton.domNode);
	  dojo.byId(where).appendChild(this.showButton.domNode);
	  	  
	  this.disable();
	  
	  dojo.subscribe("demo.provider.change", this, this.onProviderChange);
	},
	
	hideAll: function() {
		console.log("Hiding all bundles");
		dojo.forEach(bundles, function(bundle){
			if(bundle!=null){
				//If it isn't hidden already
				if(!bundle.hidden) {
					bundle.toggleHidden();
				}
			}
	    });
	},
	
	showAll: function() {
		console.log("Showing all bundles");
		dojo.forEach(bundles, function(bundle){
			if(bundle!=null){
				//If bundle is hidden make it visible
				if(bundle.hidden) {
					bundle.toggleHidden();
				}
			}
	    });
	},
	onProviderChange: function(evt){
		  console.log("OnProviderChange");
		  console.log(evt);
		  this.enable();
		  
		  this.removeAllLayoutsFromMenu();
			
		  console.log("Adding default if missing");
		  this.addDefaultLayoutIfMissing(providerSelector.getProvider());	 	  
		  this.getLayoutsForProvider(providerSelector.getProvider());
		  
		  this.layoutSelector.attr('value',"default");
	},
	removeAllLayoutsFromMenu: function(){
		  this.layoutSelector.attr('value',"");
		  var _this=this;
			function deleteItems(items, request){
				console.log("total removal query");
				console.log(items);
				console.log(request);			
				dojo.forEach(items, function(item){
					console.log("deleting "+item.name);
					_this.layouts.deleteItem(item);
				});		
			    console.log("end process");
			}
			this.layouts.fetch({query:{}, onComplete: deleteItems});
			this.layouts.save();
{'fraction_non_alphanumeric': 0.11920529801324503, 'fraction_numerical': 0.0012660693416439424, 'mean_word_length': 3.6235929761368753, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '6276645', 'n_tokens_mistral': 3220, 'n_tokens_neox': 2936, 'n_words': 955}