Best JavaScript code snippet using storybook-root
agencies.js
Source:agencies.js
1const _agencies = [2 {3 text: "alabama",4 right_text: "state",5 disabled: false,6 sub_texts: [7 { text: "alabaster", right_text: "city", disabled: false },8 { text: "auburn", right_text: "city", disabled: false },9 { text: "baldwin", right_text: "county", disabled: false },10 { text: "banks", right_text: "city", disabled: false },11 { text: "birmingham", right_text: "city", disabled: false },12 { text: "calera", right_text: "city", disabled: false },13 { text: "cullman", right_text: "county", disabled: false },14 { text: "cullman", right_text: "city", disabled: false },15 { text: "daphne", right_text: "city", disabled: false },16 { text: "de kalb", right_text: "county", disabled: false },17 { text: "decatur", right_text: "city", disabled: false },18 { text: "dodge", right_text: "city", disabled: false },19 { text: "edwardsville", right_text: "city", disabled: false },20 { text: "ethelsville", right_text: "city", disabled: false },21 { text: "eva", right_text: "city", disabled: false },22 { text: "fairview", right_text: "city", disabled: false },23 { text: "falkville", right_text: "city", disabled: false },24 { text: "foley", right_text: "city", disabled: false },25 { text: "gulf shores", right_text: "city", disabled: false },26 { text: "hartselle", right_text: "city", disabled: false },27 { text: "helena", right_text: "city", disabled: false },28 { text: "hoover", right_text: "city", disabled: false },29 { text: "hueytown", right_text: "city", disabled: false },30 { text: "huntsville", right_text: "city", disabled: false },31 { text: "irondale", right_text: "city", disabled: false },32 { text: "jasper", right_text: "city", disabled: false },33 { text: "jefferson", right_text: "county", disabled: false },34 { text: "leeds", right_text: "city", disabled: false },35 { text: "madison", right_text: "county", disabled: false },36 { text: "madison", right_text: "city", disabled: false },37 { text: "mobile", right_text: "county", disabled: false },38 { text: "mobile", right_text: "city", disabled: false },39 { text: "montgomery", right_text: "county", disabled: false },40 { text: "montgomery", right_text: "city", disabled: false },41 { text: "morgan", right_text: "county", disabled: false },42 { text: "mountain brook", right_text: "city", disabled: false },43 { text: "nauvoo", right_text: "city", disabled: false },44 { text: "northport", right_text: "city", disabled: false },45 { text: "orange beach", right_text: "city", disabled: false },46 { text: "pelham", right_text: "city", disabled: false },47 { text: "pell city", right_text: "city", disabled: false },48 { text: "piedmont", right_text: "city", disabled: false },49 { text: "prattville", right_text: "city", disabled: false },50 { text: "robertsdale", right_text: "city", disabled: false },51 { text: "saint clair", right_text: "county", disabled: false },52 { text: "shelby", right_text: "county", disabled: false },53 { text: "talladega", right_text: "city", disabled: false },54 { text: "trinity", right_text: "city", disabled: false },55 { text: "tuscaloosa", right_text: "city", disabled: false },56 { text: "tuscaloosa", right_text: "county", disabled: false },57 { text: "walker", right_text: "county", disabled: false },58 { text: "washington", right_text: "county", disabled: false },59 ],60 },61 {62 text: "alaska",63 right_text: "state",64 disabled: true,65 sub_texts: [66 { text: "adak", right_text: "city", disabled: false },67 { text: "akutan", right_text: "city", disabled: false },68 { text: "alakanuk", right_text: "city", disabled: false },69 { text: "aleknagik", right_text: "city", disabled: false },70 { text: "ambler", right_text: "city", disabled: false },71 { text: "angoon", right_text: "city", disabled: false },72 { text: "aniak", right_text: "city", disabled: false },73 { text: "bethel", right_text: "city", disabled: false },74 { text: "brevig mission", right_text: "city", disabled: false },75 { text: "buckland", right_text: "city", disabled: false },76 { text: "chefornak", right_text: "city", disabled: false },77 { text: "chevak", right_text: "city", disabled: false },78 { text: "clarks point", right_text: "city", disabled: false },79 { text: "cordova", right_text: "city", disabled: false },80 { text: "craig", right_text: "city", disabled: false },81 { text: "deering", right_text: "city", disabled: false },82 { text: "dillingham", right_text: "city", disabled: false },83 { text: "diomede", right_text: "city", disabled: false },84 { text: "eek", right_text: "city", disabled: false },85 { text: "elim", right_text: "city", disabled: false },86 { text: "emmonak", right_text: "city", disabled: false },87 { text: "false pass", right_text: "city", disabled: false },88 { text: "fort yukon", right_text: "city", disabled: false },89 { text: "galena", right_text: "city", disabled: false },90 { text: "gambell", right_text: "city", disabled: false },91 { text: "goodnews bay", right_text: "city", disabled: false },92 { text: "gustavus", right_text: "city", disabled: false },93 { text: "haines", right_text: "county", disabled: false },94 { text: "hoonah", right_text: "city", disabled: false },95 { text: "hooper bay", right_text: "city", disabled: false },96 { text: "houston", right_text: "city", disabled: false },97 { text: "hydaburg", right_text: "city", disabled: false },98 { text: "juneau", right_text: "county", disabled: false },99 { text: "kake", right_text: "city", disabled: false },100 { text: "kenai peninsula", right_text: "county", disabled: false },101 { text: "ketchikan gateway", right_text: "county", disabled: false },102 { text: "kiana", right_text: "city", disabled: false },103 { text: "king cove", right_text: "city", disabled: false },104 { text: "kivalina", right_text: "city", disabled: false },105 { text: "klawock", right_text: "city", disabled: false },106 { text: "kobuk", right_text: "city", disabled: false },107 { text: "kodiak", right_text: "city", disabled: false },108 { text: "kotlik", right_text: "city", disabled: false },109 { text: "kotzebue", right_text: "city", disabled: false },110 { text: "koyuk", right_text: "city", disabled: false },111 { text: "kwethluk", right_text: "city", disabled: false },112 { text: "larsen bay", right_text: "city", disabled: false },113 { text: "manokotak", right_text: "city", disabled: false },114 { text: "marshall", right_text: "city", disabled: false },115 { text: "mekoryuk", right_text: "city", disabled: false },116 { text: "meyers chuck", right_text: "city", disabled: false },117 { text: "mountain village", right_text: "city", disabled: false },118 { text: "napakiak", right_text: "city", disabled: false },119 { text: "napaskiak", right_text: "city", disabled: false },120 { text: "nenana", right_text: "city", disabled: false },121 { text: "nightmute", right_text: "city", disabled: false },122 { text: "nome", right_text: "city", disabled: false },123 { text: "nondalton", right_text: "city", disabled: false },124 { text: "noorvik", right_text: "city", disabled: false },125 { text: "north pole", right_text: "city", disabled: false },126 { text: "nunam iqua", right_text: "city", disabled: false },127 { text: "nunapitchuk", right_text: "city", disabled: false },128 { text: "old harbor", right_text: "city", disabled: false },129 { text: "ouzinkie", right_text: "city", disabled: false },130 { text: "palmer", right_text: "city", disabled: false },131 { text: "pelican", right_text: "city", disabled: false },132 { text: "petersburg", right_text: "city", disabled: false },133 { text: "petersburg", right_text: "county", disabled: false },134 { text: "pilot station", right_text: "city", disabled: false },135 { text: "point hope", right_text: "city", disabled: false },136 { text: "port alexander", right_text: "city", disabled: false },137 { text: "quinhagak", right_text: "city", disabled: false },138 { text: "saint george", right_text: "city", disabled: false },139 { text: "saint marys", right_text: "city", disabled: false },140 { text: "saint michael", right_text: "city", disabled: false },141 { text: "saint paul", right_text: "city", disabled: false },142 { text: "sand point", right_text: "city", disabled: false },143 { text: "savoonga", right_text: "city", disabled: false },144 { text: "scammon bay", right_text: "city", disabled: false },145 { text: "selawik", right_text: "city", disabled: false },146 { text: "shaktoolik", right_text: "city", disabled: false },147 { text: "shishmaref", right_text: "city", disabled: false },148 { text: "shungnak", right_text: "city", disabled: false },149 { text: "sitka", right_text: "county", disabled: false },150 { text: "skagway", right_text: "city", disabled: false },151 { text: "stebbins", right_text: "city", disabled: false },152 { text: "tanana", right_text: "city", disabled: false },153 { text: "teller", right_text: "city", disabled: false },154 { text: "tenakee springs", right_text: "city", disabled: false },155 { text: "thorne bay", right_text: "city", disabled: false },156 { text: "togiak", right_text: "city", disabled: false },157 { text: "toksook bay", right_text: "city", disabled: false },158 { text: "unalakleet", right_text: "city", disabled: false },159 { text: "unalaska", right_text: "city", disabled: false },160 { text: "wales", right_text: "city", disabled: false },161 { text: "wasilla", right_text: "city", disabled: false },162 { text: "white mountain", right_text: "city", disabled: false },163 { text: "whittier", right_text: "city", disabled: false },164 { text: "wrangell", right_text: "city", disabled: false },165 { text: "yakutat", right_text: "county", disabled: false },166 ],167 },168 {169 text: "arizona",170 right_text: "state",171 disabled: false,172 sub_texts: [173 {174 text: "navajo indian reservation",175 right_text: "district",176 disabled: false,177 },178 ],179 },180 { text: "arkansas", right_text: "state", disabled: false },181 { text: "california", right_text: "state", disabled: false },182 {183 text: "colorado",184 right_text: "state",185 disabled: false,186 sub_texts: [187 { text: "alamosa", right_text: "city", disabled: false },188 { text: "arvada", right_text: "city", disabled: false },189 { text: "aspen", right_text: "city", disabled: false },190 { text: "aurora", right_text: "city", disabled: false },191 { text: "avon", right_text: "city", disabled: false },192 { text: "black hawk", right_text: "city", disabled: false },193 { text: "boulder", right_text: "city", disabled: false },194 { text: "breckenridge", right_text: "city", disabled: false },195 { text: "brighton", right_text: "city", disabled: false },196 { text: "broomfield", right_text: "city", disabled: false },197 { text: "carbondale", right_text: "city", disabled: false },198 { text: "castle pines", right_text: "city", disabled: false },199 { text: "castle rock", right_text: "city", disabled: false },200 { text: "centennial", right_text: "city", disabled: false },201 { text: "central city", right_text: "city", disabled: false },202 { text: "cherry hills village", right_text: "city", disabled: false },203 { text: "colorado springs", right_text: "city", disabled: false },204 { text: "commerce city", right_text: "city", disabled: false },205 { text: "cortez", right_text: "city", disabled: false },206 { text: "craig", right_text: "city", disabled: false },207 { text: "crested butte", right_text: "city", disabled: false },208 { text: "dacono", right_text: "city", disabled: false },209 { text: "delta", right_text: "city", disabled: false },210 { text: "denver", right_text: "city", disabled: false },211 { text: "durango", right_text: "city", disabled: false },212 { text: "edgewater", right_text: "city", disabled: false },213 { text: "englewood", right_text: "city", disabled: false },214 { text: "evans", right_text: "city", disabled: false },215 { text: "federal heights", right_text: "city", disabled: false },216 { text: "fort collins", right_text: "city", disabled: false },217 { text: "frisco", right_text: "city", disabled: false },218 { text: "glendale", right_text: "city", disabled: false },219 { text: "glenwood springs", right_text: "city", disabled: false },220 { text: "golden", right_text: "city", disabled: false },221 { text: "grand junction", right_text: "city", disabled: false },222 { text: "greeley", right_text: "city", disabled: false },223 { text: "greenwood village", right_text: "city", disabled: false },224 { text: "gunnison", right_text: "city", disabled: false },225 { text: "gypsum", right_text: "city", disabled: false },226 { text: "la junta", right_text: "city", disabled: false },227 { text: "lafayette", right_text: "city", disabled: false },228 { text: "lakewood", right_text: "city", disabled: false },229 { text: "lamar", right_text: "city", disabled: false },230 { text: "larkspur", right_text: "city", disabled: false },231 { text: "littleton", right_text: "city", disabled: false },232 { text: "lone tree", right_text: "city", disabled: false },233 { text: "longmont", right_text: "city", disabled: false },234 { text: "louisville", right_text: "city", disabled: false },235 { text: "loveland", right_text: "city", disabled: false },236 { text: "montrose", right_text: "city", disabled: false },237 { text: "mount crested butte", right_text: "city", disabled: false },238 { text: "mountain village", right_text: "city", disabled: false },239 { text: "northglenn", right_text: "city", disabled: false },240 { text: "parker", right_text: "city", disabled: false },241 { text: "pueblo", right_text: "city", disabled: false },242 { text: "ridgway", right_text: "city", disabled: false },243 { text: "rifle", right_text: "city", disabled: false },244 { text: "sheridan", right_text: "city", disabled: false },245 { text: "silverthorne", right_text: "city", disabled: false },246 { text: "snowmass village", right_text: "city", disabled: false },247 { text: "steamboat springs", right_text: "city", disabled: false },248 { text: "sterling", right_text: "city", disabled: false },249 { text: "telluride", right_text: "city", disabled: false },250 { text: "thornton", right_text: "city", disabled: false },251 { text: "timnath", right_text: "city", disabled: false },252 { text: "vail", right_text: "city", disabled: false },253 { text: "westminster", right_text: "city", disabled: false },254 { text: "wheat ridge", right_text: "city", disabled: false },255 { text: "windsor", right_text: "city", disabled: false },256 { text: "winter park", right_text: "city", disabled: false },257 { text: "woodland park", right_text: "city", disabled: false },258 ],259 },260 { text: "connecticut", right_text: "state", disabled: false },261 { text: "district of columbia", right_text: "state", disabled: false },262 {263 text: "florida",264 right_text: "state",265 disabled: true,266 sub_texts: [267 { text: "panama city", right_text: "city", disabled: false },268 { text: "panama city beach", right_text: "city", disabled: false },269 ],270 },271 { text: "georgia", right_text: "state", disabled: false },272 { text: "hawaii", right_text: "state", disabled: false },273 {274 text: "idaho",275 right_text: "state",276 disabled: false,277 sub_texts: [278 { text: "donnelly", right_text: "city", disabled: false },279 { text: "driggs", right_text: "city", disabled: false },280 { text: "hailey", right_text: "city", disabled: false },281 { text: "ketchum", right_text: "city", disabled: false },282 { text: "lava hot springs", right_text: "city", disabled: false },283 { text: "mccall", right_text: "city", disabled: false },284 { text: "riggins", right_text: "city", disabled: false },285 { text: "sandpoint", right_text: "city", disabled: false },286 { text: "stanley", right_text: "city", disabled: false },287 { text: "sun valley", right_text: "city", disabled: false },288 { text: "victor", right_text: "city", disabled: false },289 ],290 },291 { text: "illinois", right_text: "state", disabled: false },292 { text: "indiana", right_text: "state", disabled: false },293 { text: "iowa", right_text: "state", disabled: false },294 { text: "kansas", right_text: "state", disabled: false },295 { text: "kentucky", right_text: "state", disabled: false },296 {297 text: "louisiana",298 right_text: "state",299 disabled: false,300 sub_texts: [301 { text: "acadia", right_text: "county", disabled: false },302 { text: "allen", right_text: "county", disabled: false },303 { text: "ascension", right_text: "county", disabled: false },304 { text: "assumption", right_text: "county", disabled: false },305 { text: "avoyelles", right_text: "county", disabled: false },306 { text: "beauregard", right_text: "county", disabled: false },307 { text: "bienville", right_text: "county", disabled: false },308 { text: "bossier", right_text: "county", disabled: false },309 { text: "caddo", right_text: "county", disabled: false },310 { text: "calcasieu", right_text: "county", disabled: false },311 { text: "caldwell", right_text: "county", disabled: false },312 { text: "cameron", right_text: "county", disabled: false },313 { text: "catahoula", right_text: "county", disabled: false },314 { text: "claiborne", right_text: "county", disabled: false },315 { text: "concordia", right_text: "county", disabled: false },316 { text: "de soto", right_text: "county", disabled: false },317 { text: "east baton rouge", right_text: "county", disabled: false },318 { text: "east carroll", right_text: "county", disabled: false },319 { text: "east feliciana", right_text: "county", disabled: false },320 { text: "evangeline", right_text: "county", disabled: false },321 { text: "franklin", right_text: "county", disabled: false },322 { text: "grant", right_text: "county", disabled: false },323 { text: "iberia", right_text: "county", disabled: false },324 { text: "iberville", right_text: "county", disabled: false },325 { text: "jackson", right_text: "county", disabled: false },326 { text: "jefferson", right_text: "county", disabled: false },327 { text: "jefferson davis", right_text: "county", disabled: false },328 { text: "la salle", right_text: "county", disabled: false },329 { text: "lafayette", right_text: "county", disabled: false },330 { text: "lafourche", right_text: "county", disabled: false },331 { text: "lincoln", right_text: "county", disabled: false },332 { text: "livingston", right_text: "county", disabled: false },333 { text: "madison", right_text: "county", disabled: false },334 { text: "morehouse", right_text: "county", disabled: false },335 { text: "natchitoches", right_text: "county", disabled: false },336 { text: "orleans", right_text: "county", disabled: false },337 { text: "ouachita", right_text: "county", disabled: false },338 { text: "plaquemines", right_text: "county", disabled: false },339 { text: "pointe coupee", right_text: "county", disabled: false },340 { text: "rapides", right_text: "county", disabled: false },341 { text: "red river", right_text: "county", disabled: false },342 { text: "richland", right_text: "county", disabled: false },343 { text: "sabine", right_text: "county", disabled: false },344 { text: "saint bernard", right_text: "county", disabled: false },345 { text: "saint charles", right_text: "county", disabled: false },346 { text: "saint helena", right_text: "county", disabled: false },347 { text: "saint james", right_text: "county", disabled: false },348 { text: "saint john the baptist", right_text: "county", disabled: false },349 { text: "saint landry", right_text: "county", disabled: false },350 { text: "saint martin", right_text: "county", disabled: false },351 { text: "saint mary", right_text: "county", disabled: false },352 { text: "saint tammany", right_text: "county", disabled: false },353 { text: "tangipahoa", right_text: "county", disabled: false },354 { text: "tensas", right_text: "county", disabled: false },355 { text: "terrebonne", right_text: "county", disabled: false },356 { text: "union", right_text: "county", disabled: false },357 { text: "vermilion", right_text: "county", disabled: false },358 { text: "vernon", right_text: "county", disabled: false },359 { text: "washington", right_text: "county", disabled: false },360 { text: "webster", right_text: "county", disabled: false },361 { text: "west baton rouge", right_text: "county", disabled: false },362 { text: "west carroll", right_text: "county", disabled: false },363 { text: "west feliciana", right_text: "county", disabled: false },364 { text: "winn", right_text: "county", disabled: false },365 ],366 },367 { text: "maine", right_text: "state", disabled: false },368 { text: "marshall islands", right_text: "state", disabled: false },369 { text: "maryland", right_text: "state", disabled: false },370 { text: "massachusetts", right_text: "state", disabled: false },371 { text: "michigan", right_text: "state", disabled: false },372 { text: "minnesota", right_text: "state", disabled: false },373 { text: "mississippi", right_text: "state", disabled: false },374 { text: "missouri", right_text: "state", disabled: false },375 { text: "nebraska", right_text: "state", disabled: false },376 { text: "nevada", right_text: "state", disabled: false },377 { text: "new jersey", right_text: "state", disabled: false },378 {379 text: "new mexico",380 right_text: "state",381 disabled: false,382 sub_texts: [383 {384 text: "navajo indian reservation",385 right_text: "district",386 disabled: false,387 },388 ],389 },390 { text: "new york", right_text: "state", disabled: false },391 { text: "north carolina", right_text: "state", disabled: false },392 { text: "north dakota", right_text: "state", disabled: false },393 { text: "ohio", right_text: "state", disabled: false },394 { text: "oklahoma", right_text: "state", disabled: false },395 { text: "pennsylvania", right_text: "state", disabled: false },396 { text: "puerto rico", right_text: "state", disabled: false },397 { text: "rhode island", right_text: "state", disabled: false },398 { text: "south carolina", right_text: "state", disabled: false },399 { text: "south dakota", right_text: "state", disabled: false },400 { text: "tennessee", right_text: "state", disabled: false },401 { text: "texas", right_text: "state", disabled: false },402 {403 text: "united states virgin islands",404 right_text: "state",405 disabled: false,406 },407 { text: "utah", right_text: "state", disabled: false },408 { text: "vermont", right_text: "state", disabled: false },409 { text: "virginia", right_text: "state", disabled: false },410 { text: "washington", right_text: "state", disabled: false },411 { text: "west virginia", right_text: "state", disabled: false },412 { text: "wisconsin", right_text: "state", disabled: false },413 { text: "wyoming", right_text: "state", disabled: false },414];415export const agencies = _agencies.map((agency) => {416 if (Array.isArray(agency.sub_texts)) {417 agency.sub_texts = agency.sub_texts.map((subText) => {418 return {419 ...subText,420 right_text: titleCase(agency.right_text),421 text: titleCase(subText.text),422 };423 });424 }425 return {426 ...agency,427 right_text: titleCase(agency.right_text),428 text: titleCase(agency.text),429 };430});431function titleCase(string) {432 return string433 .toLowerCase()434 .split(" ")435 .map((word) => {436 return word.substr(0, 1).toUpperCase() + word.substr(1, word.length);437 })438 .join(" ");...
checkbox.js
Source:checkbox.js
1var coll = document.getElementsByClassName("collapsible");2var i;3for (i = 0; i < coll.length; i++) {4 coll[i].addEventListener("click", function() {5 this.classList.toggle("activecollap");6 var content = this.nextElementSibling;7 if (content.style.display === "block") {8 content.style.display = "none";9 } else {10 content.style.display = "block";11 }12 });13}14$('#submit').click(function() {15 var cb1 = document.getElementById("checkboxgroup_g1").checked;16 var cb2 = document.getElementById("checkboxgroup_g2").checked;17 var cb3 = document.getElementById("checkboxgroup_g3").checked;18 var cb4 = document.getElementById("checkboxgroup_g4").checked;19 var cb5 = document.getElementById("checkboxgroup_g5").checked;20 var cb6 = document.getElementById("checkboxgroup_g6").checked;21 var cb7 = document.getElementById("checkboxgroup_g7").checked;22 var cb8 = document.getElementById("checkboxgroup_g8").checked;23 var cb9 = document.getElementById("checkboxgroup_g9").checked;24 if (cb1 == '' && cb2 == '' && cb3 == '' && cb4 == '' && cb5 == '' && cb6 == '' && cb7 == '' && cb8 == '' && cb9 == '') {25 alert('Required Field:Choose at least one Type of Request');26 return false;27 }28 return true;29})30$(function() {31 //Date picker,32 $(".datePicker1").datepicker({33 changeMonth: true,34 changeYear: true,35 yearRange: "1950:2020",36 dateFormat: 'M dd, yy'37 });38 $(".datePicker1").datepicker().datepicker("setDate", new Date());39 $('#datepicker2').datepicker({40 autoclose: true41 })42 $('#datepicker3').datepicker({43 autoclose: true44 })45 $('#datepicker4').datepicker({46 autoclose: true47 })48})49$(function() {50 enable_cb1();51 enable_cb2();52 enable_cb3();53 enable_cb4();54 enable_cb5();55 enable_cb6();56 enable_cb7();57 enable_cb8();58 enable_cb9();59 $("#checkboxgroup_g1").click(enable_cb1);60 $("#checkboxgroup_g2").click(enable_cb2);61 $("#checkboxgroup_g3").click(enable_cb3);62 $("#checkboxgroup_g4").click(enable_cb4);63 $("#checkboxgroup_g5").click(enable_cb5);64 $("#checkboxgroup_g6").click(enable_cb6);65 $("#checkboxgroup_g7").click(enable_cb7);66 $("#checkboxgroup_g8").click(enable_cb8);67 $("#checkboxgroup_g9").click(enable_cb9);68});69$('#cb3_4').on('change', function(e) {70 if (e.target.checked) {71 $('#myModal').modal();72 }73});74function enable_cb1() {75 if (this.checked) {76 if($('.checkboxgroup_g1').val() == '1')77 {78 $('#cb1').not(this).prop('checked', true);79 $("input.txt1").attr("disabled",true);80 $("input.txt2").attr("disabled",true);81 $("input.txt3").attr("disabled",true);82 $("input.txt4").attr("disabled",true);83 }84 // $('#others1').val('');85 // $('#others2').val('');86 // $('#others3').val('');87 $(".checkboxgroup_g1").removeAttr("disabled");88 $(".checkboxgroup_g2").attr("disabled", true);89 $(".checkboxgroup_g3").attr("disabled", true);90 $(".checkboxgroup_g4").attr("disabled", true);91 $(".checkboxgroup_g5").attr("disabled", true);92 $(".checkboxgroup_g6").attr("disabled", true);93 $(".checkboxgroup_g7").attr("disabled", true);94 $(".checkboxgroup_g8").attr("disabled", true);95 $(".checkboxgroup_g9").attr("disabled", true);96 $('.checkboxgroup_g2').not(this).prop('checked', false);97 $('.checkboxgroup_g3').not(this).prop('checked', false);98 $('.checkboxgroup_g4').not(this).prop('checked', false);99 $('.checkboxgroup_g5').not(this).prop('checked', false);100 $('.checkboxgroup_g6').not(this).prop('checked', false);101 $('.checkboxgroup_g7').not(this).prop('checked', false);102 $('.checkboxgroup_g8').not(this).prop('checked', false);103 $('.checkboxgroup_g9').not(this).prop('checked', false);104 } else {105 $('.checkboxgroup_g1').not(this).prop('checked', false);106 $(".checkboxgroup_g1").attr("disabled", true);107 $(".checkboxgroup_g2").attr("disabled", true);108 $(".checkboxgroup_g3").attr("disabled", true);109 $(".checkboxgroup_g4").attr("disabled", true);110 $(".checkboxgroup_g5").attr("disabled", true);111 $(".checkboxgroup_g6").attr("disabled", true);112 $(".checkboxgroup_g7").attr("disabled", true);113 $(".checkboxgroup_g8").attr("disabled", true);114 $(".checkboxgroup_g9").attr("disabled", true);115 }116}117function enable_cb2() {118 if (this.checked) {119 if ($('.checkboxgroup_g2').val() == '6') {120 $('#cb2').not(this).prop('checked', true);121 $("#portals").removeAttr("disabled");122 $("input.txt1").attr("disabled",true);123 $("input.txt2").attr("disabled",true);124 $("input.txt3").attr("disabled",true);125 $("input.txt4").attr("disabled",true);126 127 }128 $(".checkboxgroup_g2").removeAttr("disabled");129 $('.checkboxgroup_g1').not(this).prop('checked', false);130 $(".checkboxgroup_g1").attr("disabled", true);131 $(".checkboxgroup_g3").attr("disabled", true);132 $(".checkboxgroup_g4").attr("disabled", true);133 $(".checkboxgroup_g5").attr("disabled", true);134 $(".checkboxgroup_g6").attr("disabled", true);135 $(".checkboxgroup_g6").attr("disabled", true);136 $(".checkboxgroup_g7").attr("disabled", true);137 $(".checkboxgroup_g8").attr("disabled", true);138 $(".checkboxgroup_g9").attr("disabled", true);139 $('.checkboxgroup_g3').not(this).prop('checked', false);140 $('.checkboxgroup_g4').not(this).prop('checked', false);141 $('.checkboxgroup_g5').not(this).prop('checked', false);142 $('.checkboxgroup_g6').not(this).prop('checked', false);143 $('.checkboxgroup_g7').not(this).prop('checked', false);144 $('.checkboxgroup_g8').not(this).prop('checked', false);145 $('.checkboxgroup_g9').not(this).prop('checked', false);146 } else {147 // $('#site').val('');148 // $('#purpose').val('');149 // $('#purpose2').val('');150 $('.checkboxgroup_g2').not(this).prop('checked', false);151 $(".checkboxgroup_g1").attr("disabled", true);152 $(".checkboxgroup_g2").attr("disabled", true);153 $(".checkboxgroup_g3").attr("disabled", true);154 $(".checkboxgroup_g4").attr("disabled", true);155 $(".checkboxgroup_g5").attr("disabled", true);156 $(".checkboxgroup_g6").attr("disabled", true);157 $(".checkboxgroup_g7").attr("disabled", true);158 $(".checkboxgroup_g8").attr("disabled", true);159 $(".checkboxgroup_g9").attr("disabled", true);160 // document.getElementById("site").disabled = true;161 // document.getElementById("purpose").disabled = true;162 // document.getElementById("purpose2").disabled = true;163 }164}165function enable_cb3() {166 if (this.checked) {167 if ($('.checkboxgroup_g3').val() == '10') {168 $('#cb3').not(this).prop('checked', true);169 $("input.txt1").attr("disabled",true);170 $("input.txt2").attr("disabled",true);171 $("input.txt3").attr("disabled",true);172 $("input.txt4").attr("disabled",true);173 }174 // $('#site').val('');175 // $('#purpose').val('');176 // $('#purpose2').val('');177 // $('#softwares').val('');178 // $('#changeaccount').val('');179 // $('#others1').val('');180 // $('#others2').val('');181 // $('#others3').val('');182 $(".checkboxgroup_g3").removeAttr("disabled");183 // document.getElementById("softwares").disabled = false;184 $(".checkboxgroup_g1").attr("disabled", true);185 $(".checkboxgroup_g2").attr("disabled", true);186 $(".checkboxgroup_g4").attr("disabled", true);187 $(".checkboxgroup_g5").attr("disabled", true);188 $(".checkboxgroup_g6").attr("disabled", true);189 $(".checkboxgroup_g7").attr("disabled", true);190 $(".checkboxgroup_g8").attr("disabled", true);191 $(".checkboxgroup_g9").attr("disabled", true);192 $('.checkboxgroup_g1').not(this).prop('checked', false);193 $('.checkboxgroup_g2').not(this).prop('checked', false);194 $('.checkboxgroup_g4').not(this).prop('checked', false);195 $('.checkboxgroup_g5').not(this).prop('checked', false);196 $('.checkboxgroup_g6').not(this).prop('checked', false);197 $('.checkboxgroup_g7').not(this).prop('checked', false);198 $('.checkboxgroup_g8').not(this).prop('checked', false);199 $('.checkboxgroup_g9').not(this).prop('checked', false);200 } else {201 // document.getElementById("softwares").disabled = true;202 // $('#softwares').val('');203 $('.checkboxgroup_g3').not(this).prop('checked', false);204 $(".checkboxgroup_g1").attr("disabled", true);205 $(".checkboxgroup_g2").attr("disabled", true);206 $(".checkboxgroup_g3").attr("disabled", true);207 $(".checkboxgroup_g4").attr("disabled", true);208 $(".checkboxgroup_g5").attr("disabled", true);209 $(".checkboxgroup_g6").attr("disabled", true);210 $(".checkboxgroup_g7").attr("disabled", true);211 $(".checkboxgroup_g8").attr("disabled", true);212 $(".checkboxgroup_g9").attr("disabled", true);213 }214}215function enable_cb4() {216 if (this.checked) {217 if ($('.checkboxgroup_g4').val() == '13') {218 $('#cb4').not(this).prop('checked', true);219 $("input.txt1").removeAttr("disabled");220 $("input.txt1").prop("required",true);221 $("input.txt3").attr("disabled",true);222 $("input.txt4").attr("disabled",true);223 }224 225 226 $(".checkboxgroup_g4").removeAttr("disabled");227 $(".checkboxgroup_g1").attr("disabled", true);228 $(".checkboxgroup_g2").attr("disabled", true);229 $(".checkboxgroup_g3").attr("disabled", true);230 $(".checkboxgroup_g5").attr("disabled", true);231 $(".checkboxgroup_g6").attr("disabled", true);232 $(".checkboxgroup_g7").attr("disabled", true);233 $(".checkboxgroup_g8").attr("disabled", true);234 $(".checkboxgroup_g9").attr("disabled", true);235 $('.checkboxgroup_g1').not(this).prop('checked', false);236 $('.checkboxgroup_g2').not(this).prop('checked', false);237 $('.checkboxgroup_g3').not(this).prop('checked', false);238 $('.checkboxgroup_g5').not(this).prop('checked', false);239 $('.checkboxgroup_g6').not(this).prop('checked', false);240 $('.checkboxgroup_g7').not(this).prop('checked', false);241 $('.checkboxgroup_g8').not(this).prop('checked', false);242 $('.checkboxgroup_g9').not(this).prop('checked', false);243 244 } else {245 $('.checkboxgroup_g4').not(this).prop('checked', false);246 $("input.txt1").attr("disabled",true);247 $("input.txt2").attr("disabled",true);248 $(".checkboxgroup_g1").attr("disabled", true);249 $(".checkboxgroup_g2").attr("disabled", true);250 $(".checkboxgroup_g3").attr("disabled", true);251 $(".checkboxgroup_g4").attr("disabled", true);252 $(".checkboxgroup_g5").attr("disabled", true);253 $(".checkboxgroup_g6").attr("disabled", true);254 $(".checkboxgroup_g7").attr("disabled", true);255 $(".checkboxgroup_g8").attr("disabled", true);256 $(".checkboxgroup_g9").attr("disabled", true);257 }258}259function enable_cb5() {260 if (this.checked) {261 // document.getElementById("changeaccount").disabled = false;262 if ($('.checkboxgroup_g5').val() == '20') {263 $('#cb5').not(this).prop('checked', true);264 $("input.txt1").attr("disabled",true);265 $("input.txt2").attr("disabled",true);266 $("input.txt3").attr("disabled",true);267 $("input.txt4").attr("disabled",true);268 }269 // $('#site').val('');270 // $('#purpose').val('');271 // $('#purpose2').val('');272 // $('#softwares').val('');273 // $('#changeaccount').val('');274 $('#others1').val('');275 $('#others2').val('');276 $('#others3').val('');277 $(".checkboxgroup_g5").removeAttr("disabled");278 $(".checkboxgroup_g1").attr("disabled", true);279 $(".checkboxgroup_g2").attr("disabled", true);280 $(".checkboxgroup_g3").attr("disabled", true);281 $(".checkboxgroup_g4").attr("disabled", true);282 $(".checkboxgroup_g6").attr("disabled", true);283 $(".checkboxgroup_g7").attr("disabled", true);284 $(".checkboxgroup_g8").attr("disabled", true);285 $(".checkboxgroup_g9").attr("disabled", true);286 $('.checkboxgroup_g1').not(this).prop('checked', false);287 $('.checkboxgroup_g2').not(this).prop('checked', false);288 $('.checkboxgroup_g3').not(this).prop('checked', false);289 $('.checkboxgroup_g4').not(this).prop('checked', false);290 $('.checkboxgroup_g6').not(this).prop('checked', false);291 $('.checkboxgroup_g7').not(this).prop('checked', false);292 $('.checkboxgroup_g8').not(this).prop('checked', false);293 $('.checkboxgroup_g9').not(this).prop('checked', false);294 } else {295 // document.getElementById("changeaccount").disabled = true;296 // $('#changeaccount').val('');297 $('.checkboxgroup_g5').not(this).prop('checked', false);298 $(".checkboxgroup_g1").attr("disabled", true);299 $(".checkboxgroup_g2").attr("disabled", true);300 $(".checkboxgroup_g3").attr("disabled", true);301 $(".checkboxgroup_g4").attr("disabled", true);302 $(".checkboxgroup_g5").attr("disabled", true);303 $(".checkboxgroup_g6").attr("disabled", true);304 $(".checkboxgroup_g7").attr("disabled", true);305 $(".checkboxgroup_g8").attr("disabled", true);306 $(".checkboxgroup_g9").attr("disabled", true);307 }308}309function enable_cb6() {310 if (this.checked) {311 if($('.checkboxgroup_g6').val() == '22')312 {313 $('#cb6').not(this).prop('checked', true);314 $("input.txt1").attr("disabled",true);315 $("input.txt2").attr("disabled",true);316 $("input.txt3").attr("disabled",true);317 $("input.txt4").attr("disabled",true);318 };319 // $('#others1').val('');320 // $('#others2').val('');321 // $('#others3').val('');322 $(".checkboxgroup_g6").removeAttr("disabled");323 $(".checkboxgroup_g2").attr("disabled", true);324 $(".checkboxgroup_g3").attr("disabled", true);325 $(".checkboxgroup_g4").attr("disabled", true);326 $(".checkboxgroup_g5").attr("disabled", true);327 $(".checkboxgroup_g1").attr("disabled", true);328 $(".checkboxgroup_g7").attr("disabled", true);329 $(".checkboxgroup_g8").attr("disabled", true);330 $(".checkboxgroup_g9").attr("disabled", true);331 $('.checkboxgroup_g1').not(this).prop('checked', false);332 $('.checkboxgroup_g2').not(this).prop('checked', false);333 $('.checkboxgroup_g3').not(this).prop('checked', false);334 $('.checkboxgroup_g4').not(this).prop('checked', false);335 $('.checkboxgroup_g5').not(this).prop('checked', false);336 $('.checkboxgroup_g7').not(this).prop('checked', false);337 $('.checkboxgroup_g8').not(this).prop('checked', false);338 $('.checkboxgroup_g9').not(this).prop('checked', false);339 } else {340 $('.checkboxgroup_g6').not(this).prop('checked', false);341 $(".checkboxgroup_g1").attr("disabled", true);342 $(".checkboxgroup_g2").attr("disabled", true);343 $(".checkboxgroup_g3").attr("disabled", true);344 $(".checkboxgroup_g4").attr("disabled", true);345 $(".checkboxgroup_g5").attr("disabled", true);346 $(".checkboxgroup_g6").attr("disabled", true);347 $(".checkboxgroup_g7").attr("disabled", true);348 $(".checkboxgroup_g8").attr("disabled", true);349 $(".checkboxgroup_g9").attr("disabled", true);350 }351}352function enable_cb7() {353 if (this.checked) {354 if ($('.checkboxgroup_g7').val() == '24') {355 $('#cb7').not(this).prop('checked', true);356 $("input.txt1").attr("disabled",true);357 $("input.txt2").attr("disabled",true);358 $("input.txt3").attr("disabled",true);359 $("input.txt4").attr("disabled",true);360 }else{361 $('#cb7').not(this).prop('checked', false);362 }363 // $('#site').val('');364 // $('#purpose').val('');365 // $('#purpose2').val('');366 // $('#softwares').val('');367 // $('#changeaccount').val('');368 // $('#others1').val('');369 // $('#others2').val('');370 // $('#others3').val('');371 $(".checkboxgroup_g1").attr("disabled", true);372 $(".checkboxgroup_g2").attr("disabled", true);373 $(".checkboxgroup_g3").attr("disabled", true);374 $(".checkboxgroup_g4").attr("disabled", true);375 $(".checkboxgroup_g5").attr("disabled", true);376 $(".checkboxgroup_g6").attr("disabled", true);377 $(".checkboxgroup_g7").removeAttr("disabled");378 $(".checkboxgroup_g8").attr("disabled", true);379 $(".checkboxgroup_g9").attr("disabled", true);380 $('.checkboxgroup_g1').not(this).prop('checked', false);381 $('.checkboxgroup_g2').not(this).prop('checked', false);382 $('.checkboxgroup_g3').not(this).prop('checked', false);383 $('.checkboxgroup_g4').not(this).prop('checked', false);384 $('.checkboxgroup_g5').not(this).prop('checked', false);385 $('.checkboxgroup_g6').not(this).prop('checked', false);386 $('.checkboxgroup_g8').not(this).prop('checked', false);387 $('.checkboxgroup_g9').not(this).prop('checked', false);388 } else {389 $('.checkboxgroup_g7').not(this).prop('checked', false);390 $(".checkboxgroup_g1").attr("disabled", true);391 $(".checkboxgroup_g2").attr("disabled", true);392 $(".checkboxgroup_g3").attr("disabled", true);393 $(".checkboxgroup_g4").attr("disabled", true);394 $(".checkboxgroup_g5").attr("disabled", true);395 $(".checkboxgroup_g6").attr("disabled", true);396 $(".checkboxgroup_g7").attr("disabled", true);397 $(".checkboxgroup_g8").attr("disabled", true);398 $(".checkboxgroup_g9").attr("disabled", true);399 }400}401function enable_cb8() {402 if (this.checked) {403 if ($('.checkboxgroup_g8').val() == '32') {404 $('#cb9').not(this).prop('checked', true);405 $("input.txt1").attr("disabled",true);406 $("input.txt2").attr("disabled",true);407 $("input.txt3").attr("disabled",true);408 $("input.txt4").attr("disabled",true);409 }410 // $('#site').val('');411 // $('#purpose').val('');412 // $('#purpose2').val('');413 // $('#softwares').val('');414 // $('#changeaccount').val('');415 $('#others1').val('');416 $('#others2').val('');417 $('#others3').val('');418 $(".checkboxgroup_g1").attr("disabled", true);419 $(".checkboxgroup_g2").attr("disabled", true);420 $(".checkboxgroup_g3").attr("disabled", true);421 $(".checkboxgroup_g4").attr("disabled", true);422 $(".checkboxgroup_g5").attr("disabled", true);423 $(".checkboxgroup_g6").attr("disabled", true);424 $(".checkboxgroup_g7").attr("disabled", true);425 $(".checkboxgroup_g8").removeAttr("disabled");426 $(".checkboxgroup_g9").attr("disabled", true);427 $('.checkboxgroup_g1').not(this).prop('checked', false);428 $('.checkboxgroup_g2').not(this).prop('checked', false);429 $('.checkboxgroup_g3').not(this).prop('checked', false);430 $('.checkboxgroup_g4').not(this).prop('checked', false);431 $('.checkboxgroup_g5').not(this).prop('checked', false);432 $('.checkboxgroup_g6').not(this).prop('checked', false);433 $('.checkboxgroup_g7').not(this).prop('checked', false);434 $('.checkboxgroup_g9').not(this).prop('checked', false);435 } else {436 $('.checkboxgroup_g8').not(this).prop('checked', false);437 $(".checkboxgroup_g1").attr("disabled", true);438 $(".checkboxgroup_g2").attr("disabled", true);439 $(".checkboxgroup_g3").attr("disabled", true);440 $(".checkboxgroup_g4").attr("disabled", true);441 $(".checkboxgroup_g5").attr("disabled", true);442 $(".checkboxgroup_g6").attr("disabled", true);443 $(".checkboxgroup_g7").attr("disabled", true);444 $(".checkboxgroup_g8").attr("disabled", true);445 $(".checkboxgroup_g9").attr("disabled", true);446 }447}448function enable_cb9() {449 if (this.checked) {450 if ($('.checkboxgroup_g4').val() == '9') {451 $('#cb4').not(this).prop('checked', true);452 $("input.txt1").removeAttr("disabled");453 $("input.txt2").attr("disabled",true);454 $("input.txt3").attr("disabled",true);455 $("input.txt4").prop("required",true);456 }457 $("#others1").removeAttr("disabled");458 $("input.txt1").attr("disabled",true);459 $("input.txt2").attr("disabled",true);460 $("input.txt3").attr("disabled",true);461 $("input.txt4").attr("disabled",false);462 $(".checkboxgroup_g1").attr("disabled", true);463 $(".checkboxgroup_g2").attr("disabled", true);464 $(".checkboxgroup_g3").attr("disabled", true);465 $(".checkboxgroup_g4").attr("disabled", true);466 $(".checkboxgroup_g5").attr("disabled", true);467 $(".checkboxgroup_g6").attr("disabled", true);468 $(".checkboxgroup_g7").attr("disabled", true);469 $(".checkboxgroup_g8").attr("disabled", true);470 $(".checkboxgroup_g9").removeAttr("disabled");471 $('.checkboxgroup_g1').not(this).prop('checked', false);472 $('.checkboxgroup_g2').not(this).prop('checked', false);473 $('.checkboxgroup_g3').not(this).prop('checked', false);474 $('.checkboxgroup_g4').not(this).prop('checked', false);475 $('.checkboxgroup_g5').not(this).prop('checked', false);476 $('.checkboxgroup_g6').not(this).prop('checked', false);477 $('.checkboxgroup_g7').not(this).prop('checked', false);478 $('.checkboxgroup_g8').not(this).prop('checked', false);479 } else {480 $('.checkboxgroup_g9').not(this).prop('checked', false);481 $("input.txt1").attr("disabled",true);482 $("input.txt2").attr("disabled",true);483 $("input.txt3").attr("disabled",true);484 $("input.txt4").attr("disabled",true);485 $(".checkboxgroup_g1").attr("disabled", true);486 $(".checkboxgroup_g2").attr("disabled", true);487 $(".checkboxgroup_g3").attr("disabled", true);488 $(".checkboxgroup_g4").attr("disabled", true);489 $(".checkboxgroup_g5").attr("disabled", true);490 $(".checkboxgroup_g6").attr("disabled", true);491 $(".checkboxgroup_g7").attr("disabled", true);492 $(".checkboxgroup_g8").attr("disabled", true);493 $(".checkboxgroup_g9").attr("disabled", true);494 }495}496$('.checkboxgroup_g1').on('change', function() {497 $('.checkboxgroup_g1').not(this).prop('checked', false);498});499$('.checkboxgroup_g2').on('change', function() {500 $('.checkboxgroup_g2').not(this).prop('checked', false);501});502$('.checkboxgroup_g3').on('change', function() {503 $('.checkboxgroup_g3').not(this).prop('checked', false);504});505$('.checkboxgroup_g4').on('change', function() {506 $('.checkboxgroup_g4').not(this).prop('checked', false);507 $('.checkboxgroup_g4:checked').each(function(){508 if(this.value == "13")509 {510 $("input.txt1").removeAttr("disabled");511 512 }else if(this.value == "18")513 {514 $("input.txt1").attr("disabled",true);515 $("input.txt2").removeAttr("disabled");516 $("input.txt2").prop("required",true);517 }else{518 $("input.txt1").attr("disabled",true);519 $("input.txt2").attr("disabled",true);520 }521 }) 522});523$('.checkboxgroup_g5').on('change', function() {524 $('.checkboxgroup_g5').not(this).prop('checked', false);525});526$('.checkboxgroup_g6').on('change', function() {527 $('.checkboxgroup_g6').not(this).prop('checked', false);528 529});530$('.checkboxgroup_g7').on('change', function() {531 $('.checkboxgroup_g7').not(this).prop('checked', false);532 $('.checkboxgroup_g7:checked').each(function(){533 if(this.value == "30")534 {535 $("input.txt3").removeAttr("disabled");536 $("input.txt3").prop("required",true);537 }else{538 $("input.txt3").attr("disabled",true);539 }540 }) 541});542$('.checkbox_group').on('change', function() {543 $('.checkbox_group').not(this).prop('checked', false);544 $('.checkboxsubgroup7').not(this).prop('checked',false);545});546$('.checkboxsubgroup7').on('change', function() {547 $('.checkboxsubgroup7').not(this).prop('checked', false);548 549});550// DATE PICKER551$(function() {552 $(".datePicker1").datepicker({553 changeMonth: true,554 changeYear: true,555 yearRange: "1950:2020",556 dateFormat: 'M dd, yy'557 });558 $(".datePicker2").datepicker({559 changeMonth: true,560 changeYear: true,561 yearRange: "1950:2020",562 dateFormat: 'M dd, yy'563 });564 $(".datePicker3").datepicker({565 changeMonth: true,566 changeYear: true,567 yearRange: "1950:2020",568 dateFormat: 'M dd, yy'569 });...
quotas.py
Source:quotas.py
1# Licensed under the Apache License, Version 2.0 (the "License"); you may2# not use this file except in compliance with the License. You may obtain3# a copy of the License at4#5# http://www.apache.org/licenses/LICENSE-2.06#7# Unless required by applicable law or agreed to in writing, software8# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT9# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the10# License for the specific language governing permissions and limitations11# under the License.12from collections import defaultdict13import itertools14import logging15from django.utils.translation import ugettext_lazy as _16from horizon import exceptions17from horizon.utils.memoized import memoized18from openstack_dashboard.api import base19from openstack_dashboard.api import cinder20from openstack_dashboard.api import neutron21from openstack_dashboard.api import nova22from openstack_dashboard.contrib.developer.profiler import api as profiler23LOG = logging.getLogger(__name__)24NOVA_COMPUTE_QUOTA_FIELDS = {25 "metadata_items",26 "cores",27 "instances",28 "injected_files",29 "injected_file_content_bytes",30 "server_group_members",31 "server_groups",32 "injected_file_path_bytes",33 "ram",34 "key_pairs",35}36NOVA_NETWORK_QUOTA_FIELDS = {37 "floating_ips",38 "fixed_ips",39 "security_groups",40 "security_group_rules",41}42NOVA_QUOTA_FIELDS = NOVA_COMPUTE_QUOTA_FIELDS | NOVA_NETWORK_QUOTA_FIELDS43CINDER_QUOTA_FIELDS = {"volumes",44 "snapshots",45 "gigabytes"}46NEUTRON_QUOTA_FIELDS = {"network",47 "subnet",48 "port",49 "router",50 "floatingip",51 "security_group",52 "security_group_rule",53 }54QUOTA_FIELDS = NOVA_QUOTA_FIELDS | CINDER_QUOTA_FIELDS | NEUTRON_QUOTA_FIELDS55QUOTA_NAMES = {56 "metadata_items": _('Metadata Items'),57 "cores": _('VCPUs'),58 "instances": _('Instances'),59 "injected_files": _('Injected Files'),60 "injected_file_content_bytes": _('Injected File Content Bytes'),61 "server_group_members": _('Server Group Members'),62 "server_groups": _('Server Groups'),63 "ram": _('RAM (MB)'),64 "floating_ips": _('Floating IPs'),65 "fixed_ips": _('Fixed IPs'),66 "security_groups": _('Security Groups'),67 "security_group_rules": _('Security Group Rules'),68 "key_pairs": _('Key Pairs'),69 "injected_file_path_bytes": _('Injected File Path Bytes'),70 "volumes": _('Volumes'),71 "snapshots": _('Volume Snapshots'),72 "gigabytes": _('Total Size of Volumes and Snapshots (GB)'),73 "network": _("Networks"),74 "subnet": _("Subnets"),75 "port": _("Ports"),76 "router": _("Routers"),77 "floatingip": _('Floating IPs'),78 "security_group": _("Security Groups"),79 "security_group_rule": _("Security Group Rules")80}81class QuotaUsage(dict):82 """Tracks quota limit, used, and available for a given set of quotas."""83 def __init__(self):84 self.usages = defaultdict(dict)85 def __contains__(self, key):86 return key in self.usages87 def __getitem__(self, key):88 return self.usages[key]89 def __setitem__(self, key, value):90 raise NotImplementedError("Directly setting QuotaUsage values is not "91 "supported. Please use the add_quota and "92 "tally methods.")93 def __repr__(self):94 return repr(dict(self.usages))95 def get(self, key, default=None):96 return self.usages.get(key, default)97 def add_quota(self, quota):98 """Adds an internal tracking reference for the given quota."""99 if quota.limit is None or quota.limit == -1:100 # Handle "unlimited" quotas.101 self.usages[quota.name]['quota'] = float("inf")102 self.usages[quota.name]['available'] = float("inf")103 else:104 self.usages[quota.name]['quota'] = int(quota.limit)105 def tally(self, name, value):106 """Adds to the "used" metric for the given quota."""107 value = value or 0 # Protection against None.108 # Start at 0 if this is the first value.109 if 'used' not in self.usages[name]:110 self.usages[name]['used'] = 0111 # Increment our usage and update the "available" metric.112 self.usages[name]['used'] += int(value) # Fail if can't coerce to int.113 self.update_available(name)114 def update_available(self, name):115 """Updates the "available" metric for the given quota."""116 quota = self.usages.get(name, {}).get('quota', float('inf'))117 available = quota - self.usages[name]['used']118 if available < 0:119 available = 0120 self.usages[name]['available'] = available121def _get_quota_data(request, tenant_mode=True, disabled_quotas=None,122 tenant_id=None):123 quotasets = []124 if not tenant_id:125 tenant_id = request.user.tenant_id126 if disabled_quotas is None:127 disabled_quotas = get_disabled_quotas(request)128 qs = base.QuotaSet()129 if NOVA_QUOTA_FIELDS - disabled_quotas:130 if tenant_mode:131 quotasets.append(nova.tenant_quota_get(request, tenant_id))132 else:133 quotasets.append(nova.default_quota_get(request, tenant_id))134 if CINDER_QUOTA_FIELDS - disabled_quotas:135 try:136 if tenant_mode:137 quotasets.append(cinder.tenant_quota_get(request, tenant_id))138 else:139 quotasets.append(cinder.default_quota_get(request, tenant_id))140 except cinder.cinder_exception.ClientException:141 disabled_quotas.update(CINDER_QUOTA_FIELDS)142 msg = _("Unable to retrieve volume limit information.")143 exceptions.handle(request, msg)144 for quota in itertools.chain(*quotasets):145 if quota.name not in disabled_quotas:146 qs[quota.name] = quota.limit147 return qs148@profiler.trace149def get_default_quota_data(request, disabled_quotas=None, tenant_id=None):150 return _get_quota_data(request,151 tenant_mode=False,152 disabled_quotas=disabled_quotas,153 tenant_id=tenant_id)154@profiler.trace155def get_tenant_quota_data(request, disabled_quotas=None, tenant_id=None):156 qs = _get_quota_data(request,157 tenant_mode=True,158 disabled_quotas=disabled_quotas,159 tenant_id=tenant_id)160 # TODO(jpichon): There is no API to get the default system quotas161 # in Neutron (cf. LP#1204956), so for now handle tenant quotas here.162 # This should be handled in _get_quota_data() eventually.163 # TODO(amotoki): Purge this tricky usage.164 # openstack_dashboard/dashboards/identity/projects/views.py165 # calls get_tenant_quota_data directly and it expects166 # neutron data is not returned.167 if not disabled_quotas:168 return qs169 # Check if neutron is enabled by looking for network170 if not (NEUTRON_QUOTA_FIELDS - disabled_quotas):171 return qs172 tenant_id = tenant_id or request.user.tenant_id173 neutron_quotas = neutron.tenant_quota_get(request, tenant_id)174 if 'floating_ips' in disabled_quotas:175 if 'floatingip' not in disabled_quotas:176 # Rename floatingip to floating_ips since that's how it's177 # expected in some places (e.g. Security & Access' Floating IPs)178 fips_quota = neutron_quotas.get('floatingip').limit179 qs.add(base.QuotaSet({'floating_ips': fips_quota}))180 if 'security_groups' in disabled_quotas:181 if 'security_group' not in disabled_quotas:182 # Rename security_group to security_groups since that's how it's183 # expected in some places (e.g. Security & Access' Security Groups)184 sec_quota = neutron_quotas.get('security_group').limit185 qs.add(base.QuotaSet({'security_groups': sec_quota}))186 if 'network' in disabled_quotas:187 for item in qs.items:188 if item.name == 'networks':189 qs.items.remove(item)190 break191 else:192 net_quota = neutron_quotas.get('network').limit193 qs.add(base.QuotaSet({'networks': net_quota}))194 if 'subnet' in disabled_quotas:195 for item in qs.items:196 if item.name == 'subnets':197 qs.items.remove(item)198 break199 else:200 net_quota = neutron_quotas.get('subnet').limit201 qs.add(base.QuotaSet({'subnets': net_quota}))202 if 'router' in disabled_quotas:203 for item in qs.items:204 if item.name == 'routers':205 qs.items.remove(item)206 break207 else:208 router_quota = neutron_quotas.get('router').limit209 qs.add(base.QuotaSet({'routers': router_quota}))210 return qs211@profiler.trace212def get_disabled_quotas(request):213 disabled_quotas = set([])214 # Cinder215 if not cinder.is_volume_service_enabled(request):216 disabled_quotas.update(CINDER_QUOTA_FIELDS)217 # Neutron218 if not base.is_service_enabled(request, 'network'):219 disabled_quotas.update(NEUTRON_QUOTA_FIELDS)220 else:221 # Remove the nova network quotas222 disabled_quotas.update(['floating_ips', 'fixed_ips'])223 if neutron.is_extension_supported(request, 'security-group'):224 # If Neutron security group is supported, disable Nova quotas225 disabled_quotas.update(['security_groups', 'security_group_rules'])226 else:227 # If Nova security group is used, disable Neutron quotas228 disabled_quotas.update(['security_group', 'security_group_rule'])229 if not neutron.is_router_enabled(request):230 disabled_quotas.update(['router', 'floatingip'])231 try:232 if not neutron.is_quotas_extension_supported(request):233 disabled_quotas.update(NEUTRON_QUOTA_FIELDS)234 except Exception:235 LOG.exception("There was an error checking if the Neutron "236 "quotas extension is enabled.")237 # Nova238 if not (base.is_service_enabled(request, 'compute') and239 nova.can_set_quotas()):240 disabled_quotas.update(NOVA_QUOTA_FIELDS)241 # There appear to be no glance quota fields currently242 return disabled_quotas243def _add_usage_if_quota_enabled(usage, name, value, disabled_quotas):244 if name in disabled_quotas:245 return246 usage.tally(name, value)247@profiler.trace248def _get_tenant_compute_usages(request, usages, disabled_quotas, tenant_id):249 enabled_compute_quotas = NOVA_COMPUTE_QUOTA_FIELDS - disabled_quotas250 if not enabled_compute_quotas:251 return252 # Unlike the other services it can be the case that nova is enabled but253 # doesn't support quotas, in which case we still want to get usage info,254 # so don't rely on '"instances" in disabled_quotas' as elsewhere255 if not base.is_service_enabled(request, 'compute'):256 return257 if tenant_id and tenant_id != request.user.project_id:258 # all_tenants is required when querying about any project the user is259 # not currently scoped to260 instances, has_more = nova.server_list(261 request, search_opts={'tenant_id': tenant_id, 'all_tenants': True})262 else:263 instances, has_more = nova.server_list(request)264 _add_usage_if_quota_enabled(usages, 'instances', len(instances),265 disabled_quotas)266 if {'cores', 'ram'} - disabled_quotas:267 # Fetch deleted flavors if necessary.268 flavors = dict([(f.id, f) for f in nova.flavor_list(request)])269 missing_flavors = [instance.flavor['id'] for instance in instances270 if instance.flavor['id'] not in flavors]271 for missing in missing_flavors:272 if missing not in flavors:273 try:274 flavors[missing] = nova.flavor_get(request, missing)275 except Exception:276 flavors[missing] = {}277 exceptions.handle(request, ignore=True)278 # Sum our usage based on the flavors of the instances.279 for flavor in [flavors[instance.flavor['id']]280 for instance in instances]:281 _add_usage_if_quota_enabled(282 usages, 'cores', getattr(flavor, 'vcpus', None),283 disabled_quotas)284 _add_usage_if_quota_enabled(285 usages, 'ram', getattr(flavor, 'ram', None),286 disabled_quotas)287 # Initialize the tally if no instances have been launched yet288 if len(instances) == 0:289 _add_usage_if_quota_enabled(usages, 'cores', 0, disabled_quotas)290 _add_usage_if_quota_enabled(usages, 'ram', 0, disabled_quotas)291@profiler.trace292def _get_tenant_network_usages(request, usages, disabled_quotas, tenant_id):293 enabled_quotas = ((NOVA_NETWORK_QUOTA_FIELDS | NEUTRON_QUOTA_FIELDS)294 - disabled_quotas)295 if not enabled_quotas:296 return297 # NOTE(amotoki): floatingip is Neutron quota and floating_ips is298 # Nova quota. We need to check both.299 if {'floatingip', 'floating_ips'} & enabled_quotas:300 floating_ips = []301 try:302 if neutron.floating_ip_supported(request):303 floating_ips = neutron.tenant_floating_ip_list(request)304 except Exception:305 pass306 usages.tally('floating_ips', len(floating_ips))307 if 'security_group' not in disabled_quotas:308 security_groups = []309 security_groups = neutron.security_group_list(request)310 usages.tally('security_groups', len(security_groups))311 if 'network' not in disabled_quotas:312 networks = neutron.network_list(request, tenant_id=tenant_id)313 usages.tally('networks', len(networks))314 if 'subnet' not in disabled_quotas:315 subnets = neutron.subnet_list(request, tenant_id=tenant_id)316 usages.tally('subnets', len(subnets))317 if 'router' not in disabled_quotas:318 routers = neutron.router_list(request, tenant_id=tenant_id)319 usages.tally('routers', len(routers))320@profiler.trace321def _get_tenant_volume_usages(request, usages, disabled_quotas, tenant_id):322 if CINDER_QUOTA_FIELDS - disabled_quotas:323 try:324 if tenant_id:325 opts = {'all_tenants': 1, 'project_id': tenant_id}326 volumes = cinder.volume_list(request, opts)327 snapshots = cinder.volume_snapshot_list(request, opts)328 else:329 volumes = cinder.volume_list(request)330 snapshots = cinder.volume_snapshot_list(request)331 volume_usage = sum([int(v.size) for v in volumes])332 snapshot_usage = sum([int(s.size) for s in snapshots])333 _add_usage_if_quota_enabled(334 usages, 'gigabytes', (snapshot_usage + volume_usage),335 disabled_quotas)336 _add_usage_if_quota_enabled(337 usages, 'volumes', len(volumes), disabled_quotas)338 _add_usage_if_quota_enabled(339 usages, 'snapshots', len(snapshots), disabled_quotas)340 except cinder.cinder_exception.ClientException:341 msg = _("Unable to retrieve volume limit information.")342 exceptions.handle(request, msg)343NETWORK_QUOTA_API_KEY_MAP = {344 'floating_ips': ['floatingip', 'floating_ips'],345 'security_groups': ['security_group', 'security_groups'],346 'security_group_rules': ['security_group_rule', 'security_group_rules'],347 # Singular form key is used as quota field in the Neutron API.348 # We convert it explicitly here.349 # NOTE(amotoki): It is better to be converted in the horizon API wrapper350 # layer. Ideally the REST APIs of back-end services are consistent.351 'networks': ['network'],352 'subnets': ['subnet'],353 'ports': ['port'],354 'routers': ['router'],355}356def _convert_targets_to_quota_keys(targets):357 quota_keys = set()358 for target in targets:359 if target in NETWORK_QUOTA_API_KEY_MAP:360 quota_keys.update(NETWORK_QUOTA_API_KEY_MAP[target])361 continue362 if target in QUOTA_FIELDS:363 quota_keys.add(target)364 continue365 raise ValueError('"%s" is not a valid quota field name.' % target)366 return quota_keys367@profiler.trace368@memoized369def tenant_quota_usages(request, tenant_id=None, targets=None):370 """Get our quotas and construct our usage object.371 :param tenant_id: Target tenant ID. If no tenant_id is provided,372 a the request.user.project_id is assumed to be used.373 :param targets: A tuple of quota names to be retrieved.374 If unspecified, all quota and usage information is retrieved.375 """376 if not tenant_id:377 tenant_id = request.user.project_id378 disabled_quotas = get_disabled_quotas(request)379 usages = QuotaUsage()380 if targets:381 enabled_quotas = set(QUOTA_FIELDS) - disabled_quotas382 enabled_quotas &= _convert_targets_to_quota_keys(targets)383 disabled_quotas = set(QUOTA_FIELDS) - enabled_quotas384 for quota in get_tenant_quota_data(request,385 disabled_quotas=disabled_quotas,386 tenant_id=tenant_id):387 usages.add_quota(quota)388 # Get our usages.389 _get_tenant_compute_usages(request, usages, disabled_quotas, tenant_id)390 _get_tenant_network_usages(request, usages, disabled_quotas, tenant_id)391 _get_tenant_volume_usages(request, usages, disabled_quotas, tenant_id)392 # Server Group usage393 if 'server_groups' not in disabled_quotas:394 server_groups = []395 try:396 server_groups = nova.server_group_list(request)397 except Exception:398 pass399 for server_group in server_groups:400 project_id = getattr(server_group, 'project_id', None)401 setattr(server_group, 'project_id', project_id)402 usages.tally('server_groups', len([server_group for server_group in403 server_groups if404 server_group.project_id ==405 request.user.tenant_id]))406 return usages407@profiler.trace408def tenant_limit_usages(request):409 # TODO(licostan): This method shall be removed from Quota module.410 # ProjectUsage/BaseUsage maybe used instead on volume/image dashboards.411 limits = {}412 try:413 if base.is_service_enabled(request, 'compute'):414 limits.update(nova.tenant_absolute_limits(request, reserved=True))415 except Exception:416 msg = _("Unable to retrieve compute limit information.")417 exceptions.handle(request, msg)418 if cinder.is_volume_service_enabled(request):419 try:420 limits.update(cinder.tenant_absolute_limits(request))421 except cinder.cinder_exception.ClientException:422 msg = _("Unable to retrieve volume limit information.")423 exceptions.handle(request, msg)424 return limits425def enabled_quotas(request):426 """Returns the list of quotas available minus those that are disabled"""...
seckit.listener.js
Source:seckit.listener.js
1// TODO: This code could likely all be converted to Form API #states2// (allowing us to remove this file entirely).3// https://api.drupal.org/api/drupal/includes!common.inc/function/drupal_process_states/8.2.x4Drupal.behaviors.seckit = {5 attach: function(context) {6 seckit_listener_hsts(context);7 seckit_listener_csp(context);8 seckit_listener_origin(context);9 seckit_listener_clickjacking_x_frame(context);10 seckit_listener_clickjacking_noscript(context);11 seckit_listener_various(context);12 (function ($) {13 $('#edit-seckit-ssl-hsts', context).click(function () {14 seckit_listener_hsts(context);15 });16 $('#edit-seckit-xss-csp-checkbox', context).click(function () {17 seckit_listener_csp(context);18 });19 $('#edit-seckit-xss-csp-policy-uri', context).blur(function () {20 seckit_listener_csp(context);21 });22 $('#edit-seckit-csrf-origin', context).click(function () {23 seckit_listener_origin(context);24 });25 $('#edit-seckit-clickjacking-x-frame', context).change(function () {26 seckit_listener_clickjacking_x_frame(context);27 });28 $('#edit-seckit-clickjacking-js-css-noscript', context).click(function () {29 seckit_listener_clickjacking_noscript(context);30 });31 $('#edit-seckit-various-from-origin', context).click(function () {32 seckit_listener_various(context);33 });34 $('#edit-seckit-various-referrer-policy', context).click(function () {35 seckit_listener_various(context);36 });37 })(jQuery);38 }39};40/**41 * Adds/removes attributes for input fields in42 * SSL/TLS fieldset for HTTP Strict Transport Security.43 */44function seckit_listener_hsts(context) {45 (function ($) {46 if ($('#edit-seckit-ssl-hsts').is(':checked')) {47 $('#edit-seckit-ssl-hsts-max-age', context).removeAttr('disabled');48 $('#edit-seckit-ssl-hsts-subdomains', context).removeAttr('disabled');49 $('#edit-seckit-ssl-hsts-preload', context).removeAttr('disabled');50 $('label[for="edit-seckit-ssl-hsts-max-age"]', context).append('<span title="' + Drupal.t('This field is required.') + '" class="form-required">*</span>');51 }52 else {53 $('#edit-seckit-ssl-hsts-max-age', context).attr('disabled', 'disabled');54 $('#edit-seckit-ssl-hsts-subdomains', context).attr('disabled', 'disabled');55 $('#edit-seckit-ssl-hsts-preload', context).attr('disabled', 'disabled');56 $('label[for="edit-seckit-ssl-hsts-max-age"] > span', context).remove();57 }58 })(jQuery);59}60/**61 * Adds/removes attributes for input fields in62 * Content Security Policy fieldset.63 */64function seckit_listener_csp(context) {65 (function ($) {66 var checkbox_status = $('#edit-seckit-xss-csp-checkbox').is(':checked');67 var policy_uri_status = $('#edit-seckit-xss-csp-policy-uri').val().length === 0;68 if (checkbox_status) {69 $('#edit-seckit-xss-csp-report-only', context).removeAttr('disabled');70 $('#edit-seckit-xss-csp-policy-uri', context).removeAttr('disabled');71 if (!policy_uri_status) {72 _seckit_csp_add_attributes(context);73 }74 else {75 _seckit_csp_remove_attributes(context);76 }77 }78 else {79 $('#edit-seckit-xss-csp-report-only', context).attr('disabled', 'disabled');80 $('#edit-seckit-xss-csp-policy-uri', context).attr('disabled', 'disabled');81 _seckit_csp_add_attributes(context);82 }83 })(jQuery);84}85/**86 * Removes attributes for CSP input fields.87 */88function _seckit_csp_remove_attributes(context) {89 (function ($) {90 $('#edit-seckit-xss-csp-default-src', context).removeAttr('disabled');91 $('#edit-seckit-xss-csp-script-src', context).removeAttr('disabled');92 $('#edit-seckit-xss-csp-object-src', context).removeAttr('disabled');93 $('#edit-seckit-xss-csp-style-src', context).removeAttr('disabled');94 $('#edit-seckit-xss-csp-img-src', context).removeAttr('disabled');95 $('#edit-seckit-xss-csp-media-src', context).removeAttr('disabled');96 $('#edit-seckit-xss-csp-frame-src', context).removeAttr('disabled');97 $('#edit-seckit-xss-csp-frame-ancestors', context).removeAttr('disabled');98 $('#edit-seckit-xss-csp-child-src', context).removeAttr('disabled');99 $('#edit-seckit-xss-csp-font-src', context).removeAttr('disabled');100 $('#edit-seckit-xss-csp-connect-src', context).removeAttr('disabled');101 $('#edit-seckit-xss-csp-report-uri', context).removeAttr('disabled');102 })(jQuery);103}104/**105 * Adds attributes for CSP input fields.106 */107function _seckit_csp_add_attributes(context) {108 (function ($) {109 $('#edit-seckit-xss-csp-default-src', context).attr('disabled', 'disabled');110 $('#edit-seckit-xss-csp-script-src', context).attr('disabled', 'disabled');111 $('#edit-seckit-xss-csp-object-src', context).attr('disabled', 'disabled');112 $('#edit-seckit-xss-csp-style-src', context).attr('disabled', 'disabled');113 $('#edit-seckit-xss-csp-img-src', context).attr('disabled', 'disabled');114 $('#edit-seckit-xss-csp-media-src', context).attr('disabled', 'disabled');115 $('#edit-seckit-xss-csp-frame-src', context).attr('disabled', 'disabled');116 $('#edit-seckit-xss-csp-frame-ancestors', context).attr('disabled', 'disabled');117 $('#edit-seckit-xss-csp-child-src', context).attr('disabled', 'disabled');118 $('#edit-seckit-xss-csp-font-src', context).attr('disabled', 'disabled');119 $('#edit-seckit-xss-csp-connect-src', context).attr('disabled', 'disabled');120 $('#edit-seckit-xss-csp-report-uri', context).attr('disabled', 'disabled');121 })(jQuery);122}123/**124 * Adds/removes attributes for input fields in125 * Cross-site Request Forgery fieldset for HTTP Origin.126 */127function seckit_listener_origin(context) {128 (function ($) {129 if ($('#edit-seckit-csrf-origin').is(':checked')) {130 $('#edit-seckit-csrf-origin-whitelist', context).removeAttr('disabled');131 }132 else {133 $('#edit-seckit-csrf-origin-whitelist', context).attr('disabled', 'disabled');134 }135 })(jQuery);136}137/**138 * Adds/removes attributes for input fields in139 * Clickjacking "X-Frame-Options" fields.140 */141function seckit_listener_clickjacking_x_frame(context) {142 (function ($) {143 if ($('#edit-seckit-clickjacking-x-frame').find(":selected").text() == 'ALLOW-FROM') {144 $('#edit-seckit-clickjacking-x-frame-allow-from', context).removeAttr('disabled');145 $('label[for="edit-seckit-clickjacking-x-frame-allow-from"]', context).append('<span title="' + Drupal.t('This field is required.') + '" class="form-required">*</span>');146 }147 else {148 $('#edit-seckit-clickjacking-x-frame-allow-from', context).attr('disabled', 'disabled');149 $('label[for="edit-seckit-clickjacking-x-frame-allow-from"] > span', context).remove();150 }151 })(jQuery);152}153/**154 * Adds/removes attributes for input fields in155 * Clickjacking NoScript fields.156 */157function seckit_listener_clickjacking_noscript(context) {158 (function ($) {159 if ($('#edit-seckit-clickjacking-js-css-noscript').is(':checked')) {160 $('#edit-seckit-clickjacking-noscript-message', context).removeAttr('disabled');161 }162 else {163 $('#edit-seckit-clickjacking-noscript-message', context).attr('disabled', 'disabled');164 }165 })(jQuery);166}167/**168 * Adds/removes attributes for input fields in169 * Various fieldset.170 */171function seckit_listener_various(context) {172 (function ($) {173 if ($('#edit-seckit-various-from-origin').is(':checked')) {174 $('#edit-seckit-various-from-origin-destination', context).removeAttr('disabled');175 }176 else {177 $('#edit-seckit-various-from-origin-destination', context).attr('disabled', 'disabled');178 }179 if ($('#edit-seckit-various-referrer-policy').is(':checked')) {180 $('#edit-seckit-various-referrer-policy-policy', context).removeAttr('disabled');181 }182 else {183 $('#edit-seckit-various-referrer-policy-policy', context).attr('disabled', 'disabled');184 }185 })(jQuery);...
disable_sql.py
Source:disable_sql.py
1import threading2from sqlalchemy import Column, String, UnicodeText, func, distinct3from tg_bot.modules.sql import SESSION, BASE4class Disable(BASE):5 __tablename__ = "disabled_commands"6 chat_id = Column(String(14), primary_key=True)7 command = Column(UnicodeText, primary_key=True)8 def __init__(self, chat_id, command):9 self.chat_id = chat_id10 self.command = command11 def __repr__(self):12 return "Disabled cmd {} in {}".format(self.command, self.chat_id)13Disable.__table__.create(checkfirst=True)14DISABLE_INSERTION_LOCK = threading.RLock()15DISABLED = {}16def disable_command(chat_id, disable):17 with DISABLE_INSERTION_LOCK:18 disabled = SESSION.query(Disable).get((str(chat_id), disable))19 if not disabled:20 DISABLED.setdefault(str(chat_id), set()).add(disable)21 disabled = Disable(str(chat_id), disable)22 SESSION.add(disabled)23 SESSION.commit()24 return True25 SESSION.close()26 return False27def enable_command(chat_id, enable):28 with DISABLE_INSERTION_LOCK:29 disabled = SESSION.query(Disable).get((str(chat_id), enable))30 if disabled:31 if enable in DISABLED.get(str(chat_id)): # sanity check32 DISABLED.setdefault(str(chat_id), set()).remove(enable)33 SESSION.delete(disabled)34 SESSION.commit()35 return True36 SESSION.close()37 return False38def is_command_disabled(chat_id, cmd):39 return str(cmd).lower() in DISABLED.get(str(chat_id), set())40def get_all_disabled(chat_id):41 return DISABLED.get(str(chat_id), set())42def num_chats():43 try:44 return SESSION.query(func.count(distinct(Disable.chat_id))).scalar()45 finally:46 SESSION.close()47def num_disabled():48 try:49 return SESSION.query(Disable).count()50 finally:51 SESSION.close()52def migrate_chat(old_chat_id, new_chat_id):53 with DISABLE_INSERTION_LOCK:54 chats = SESSION.query(Disable).filter(Disable.chat_id == str(old_chat_id)).all()55 for chat in chats:56 chat.chat_id = str(new_chat_id)57 SESSION.add(chat)58 if str(old_chat_id) in DISABLED:59 DISABLED[str(new_chat_id)] = DISABLED.get(str(old_chat_id), set())60 SESSION.commit()61def __load_disabled_commands():62 global DISABLED63 try:64 all_chats = SESSION.query(Disable).all()65 for chat in all_chats:66 DISABLED.setdefault(chat.chat_id, set()).add(chat.command)67 finally:68 SESSION.close()...
Using AI Code Generation
1import React from 'react';2import { storiesOf } from '@storybook/react';3import { action } from '@storybook/addon-actions';4import { linkTo } from '@storybook/addon-links';5import { Button, Welcome } from '@storybook/react/demo';6storiesOf('Welcome', module).add('to Storybook', () => <Welcome showApp={linkTo('Button')} />);7storiesOf('Button', module)8 .add('with text', () => (9 <Button onClick={action('clicked')}>Hello Button</Button>10 .add('with some emoji', () => (11 <Button onClick={action('clicked')}>😀 😎 👍 💯</Button>12 .add('Disabled', () => (13 <Button disabled onClick={action('clicked')}>Hello Button</Button>14 .add('Disabled with some emoji', () => (15 <Button disabled onClick={action('clicked')}>😀 😎 👍 💯</Button>16 ));17import React from 'react';18import { configure, shallow } from 'enzyme';19import Adapter from 'enzyme-adapter-react-16';20import Button from '@storybook/react/demo';21configure({ adapter: new Adapter() });22describe('<Button />', () => {23 it('should render 2 buttons', () => {24 const wrapper = shallow(<Button />);25 expect(wrapper.find('button')).toHaveLength(2);26 });27 it('should render disabled button', () => {28 const wrapper = shallow(<Button disabled />);29 expect(wrapper.find('button[disabled]')).toHaveLength(1);30 });31});
Using AI Code Generation
1import React from 'react';2import { storiesOf } from '@storybook/react';3import { withInfo } from '@storybook/addon-info';4import { withDisabled } from 'storybook-addon-disabled';5const stories = storiesOf('Button', module).addDecorator(6 withInfo({7 styles: {8 infoBody: {9 },10 },11 })12);13stories.add(14 withDisabled(() => <button>Disabled Button</button>, {15 })16);17stories.add(18 withDisabled(() => <button>Disabled Button</button>, {19 })20);21stories.add(22 withDisabled(() => <button onClick={action('clicked')}>Disabled Button</button>, {23 })24);25stories.add(26 withDisabled(() => <button onClick={action('clicked')}>Disabled Button</button>, {27 })28);29stories.add(30 withDisabled(() => <button onClick={action('clicked')}>Disabled Button</button>, {31 })32);33stories.add(34 withDisabled(() => <button onClick={action('clicked')}>Disabled Button</button>, {35 })36);
Using AI Code Generation
1import { Disabled } from "storybook-root";2import { storiesOf } from "@storybook/react";3import React from "react";4import { action } from "@storybook/addon-actions";5storiesOf("Button", module)6 .add("with text", () => (7 <button onClick={action("clicked")}>Hello Button</button>8 .add("Disabled", () => (9 <button onClick={action("clicked")}>Hello Button</button>10 .add("with some emoji", () => (11 <button onClick={action("clicked")}>12 ));
Using AI Code Generation
1import { Disabled } from 'storybook-root';2import React from 'react';3import ReactDOM from 'react-dom';4ReactDOM.render(5 document.getElementById('root')6);7import Disabled from 'storybook-root';8import React from 'react';9import ReactDOM from 'react-dom';10ReactDOM.render(11 document.getElementById('root')12);13import { Disabled } from 'storybook-root';14import React from 'react';15import ReactDOM from 'react-dom';16ReactDOM.render(17 document.getElementById('root')18);19var Disabled = require('storybook-root').Disabled;20var React = require('react');21var ReactDOM = require('react-dom');22ReactDOM.render(23 document.getElementById('root')24);
Using AI Code Generation
1import { addDecorator } from "@storybook/react";2import { Disabled } from "storybook-root-decorator";3addDecorator(Disabled);4import { addDecorator } from "@storybook/react";5import { Disabled } from "storybook-root-decorator";6addDecorator(Disabled);7export default {8};9export const TestStory = () => <Test />;10![Disabled Story](./assets/Disabled.png)
Using AI Code Generation
1import React from 'react';2import PropTypes from 'prop-types';3import { useTheme } from '@material-ui/core/styles';4import { useMediaQuery } from '@material-ui/core';5const Disabled = ({ children }) => {6 const theme = useTheme();7 const isDesktop = useMediaQuery(theme.breakpoints.up('sm'));8 if (isDesktop) {9 return <>{children}</>;10 }11 return null;12};13Disabled.propTypes = {14};15export default Disabled;16import React from 'react';17import { addDecorator } from '@storybook/react';18import { ThemeProvider } from '@material-ui/core/styles';19import { MemoryRouter } from 'react-router-dom';20import { theme } from './theme';21import { Disabled } from 'storybook-root';22addDecorator((story) => (23 <MemoryRouter initialEntries={['/']}>24 <ThemeProvider theme={theme}>25 {story()}26));27import React from 'react';28import { addDecorator } from '@storybook/react';29import { ThemeProvider } from '@material-ui/core/styles';30import { MemoryRouter } from 'react-router-dom';31import { theme } from './theme';32import { Disabled } from 'storybook-root';33addDecorator((story) => (34 <MemoryRouter initialEntries={['/']}>35 <ThemeProvider theme={theme}>
Using AI Code Generation
1export default {2 (story) => {3 return <div style={{ backgroundColor: "blue" }}>{story()}</div>;4 },5 parameters: {6 },7};8export const Default = () => <button>Default</button>;9export default {10 (story) => {11 return <div style={{ backgroundColor: "blue" }}>{story()}</div>;12 },13 parameters: {14 },15};16export const Default = () => <button>Default</button>;17Default.parameters = {18};19export default {20 (story) => {21 return <div style={{ backgroundColor: "blue" }}>{story()}</div>;22 },23 parameters: {24 },25};26export const Default = () => <button>Default</button>;27Default.parameters = {28};29export default {30 (story) => {31 return <div style={{ backgroundColor: "blue" }}>{story()}</div>;32 },33 parameters: {34 },35};36export const Default = () => <button>Default</button>;37Default.parameters = {38};
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!