Skip to content

Commit

Permalink
Major updates
Browse files Browse the repository at this point in the history
* Added Search
* Added ability to toggle off columns
* Added German translation pack
* Added ability to show overall progress
  • Loading branch information
Raylehnhoff committed Oct 3, 2015
1 parent 28106f1 commit 83da068
Show file tree
Hide file tree
Showing 7 changed files with 5,999 additions and 255 deletions.
1 change: 1 addition & 0 deletions scripts/footerScripts.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var pageViewModel;

$(document).ready(function () {
pageViewModel = new Kanai.VM.Site();
pageViewModel.init();
Expand Down
5,581 changes: 5,472 additions & 109 deletions scripts/knockout-3.3.0.js

Large diffs are not rendered by default.

65 changes: 59 additions & 6 deletions tscripts/VM/items.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
/// <reference path="../jquery.d.ts"/>
/// <reference path="../models/equipment.ts"/>
/// <reference path="../lang.ts" />
/// <reference path="../includes.d.ts"/>
var Kanai;
(function (Kanai) {
var VM;
(function (VM) {
var Site = (function () {
function Site() {
this.localStorageString = "kanai_cube";
var self = this;
this.Weapons = ko.observableArray();
this.Jewelry = ko.observableArray();
Expand All @@ -19,12 +21,44 @@ var Kanai;
this.hideNonSeasonalCheckboxes = ko.observable(false).extend({ notify: 'always' });
this.hideSeasonalCheckboxes = ko.observable(false).extend({ notify: 'always' });
this.seasonalProgressBar = ko.observable(true).extend({ notify: 'always' });
this.bothProgressBar = ko.observable(false).extend({ notify: 'always' });
this.AllWeapons = new Array();
this.AllJewelry = new Array();
this.AllArmor = new Array();
this.Export = ko.observable();
this.Import = ko.observable();
this.Search = ko.observable('').extend({ notify: 'always', rateLimit: 200 });
this.FilteredArray = ko.observableArray([]);
this.Search.subscribe(function (searchText) {
if (searchText && searchText.length >= 2) {
//we need to search the array
self.FilteredArray([]);
self.searchArray(self.Armor, searchText, self.FilteredArray);
self.searchArray(self.Weapons, searchText, self.FilteredArray);
self.searchArray(self.Jewelry, searchText, self.FilteredArray);
if (self.FilteredArray().length > 0) {
self.FilteredArray.valueHasMutated();
$("a[href='#panel-search']").tab("show");
}
}
else {
$("a[href='#panel-armor']").tab("show");
self.FilteredArray([]);
$(".sticky").removeClass('sticky');
$(".sticky-progress").removeClass("sticky-progress");
$(".sticky-table").removeClass('sticky-table');
}
});
}
Site.prototype.searchArray = function (array, searchText, response) {
var res = ko.utils.arrayFilter(array(), function (item) {
var lowerItemName = ko.unwrap(item.itemName).toString().toLowerCase();
var lowerAffix = ko.unwrap(item.affix).toString().toLowerCase();
return (lowerItemName.indexOf(searchText) !== -1) || (lowerAffix.indexOf(searchText) !== -1);
});
ko.utils.arrayPushAll(response(), res);
return res.length > 0;
};
Site.prototype.clear = function () {
this.Weapons([]);
this.Jewelry([]);
Expand All @@ -33,7 +67,7 @@ var Kanai;
Site.prototype.init = function () {
var _this = this;
var self = this;
var vm = JSON.parse(localStorage.getItem("kanai_cube"));
var vm = JSON.parse(localStorage.getItem(self.localStorageString));
if (!vm) {
this.loadWeapons(self.Weapons);
this.loadJewelry(self.Jewelry);
Expand All @@ -50,7 +84,7 @@ var Kanai;
this.Jewelry.sort(function (left, right) {
return left().itemName() == right().itemName() ? 0 : (left().itemName() < right().itemName() ? -1 : 1);
});
localStorage.setItem("kanai_cube", ko.mapping.toJSON(this));
localStorage.setItem(self.localStorageString, ko.mapping.toJSON(this));
$.each(self.Armor(), function (i, elem) {
elem().isCubedSeason.subscribe(function (newValue) {
self.saveToLocalStorage();
Expand Down Expand Up @@ -101,7 +135,7 @@ var Kanai;
self.Jewelry = ko.observableArray();
}
}
ko.mapping.fromJS(vm, { "include": ["hideCubed", "hideCubedNonSeason", "nonSeasonalProgressBar", "seasonalProgressBar"] }, self);
ko.mapping.fromJS(vm, { "include": ["hideCubed", "hideCubedNonSeason", "nonSeasonalProgressBar", "seasonalProgressBar", "bothProgressBar"] }, self);
this.checkConsistency();
this.saveToLocalStorage();
$.each(self.Armor(), function (i, elem) {
Expand Down Expand Up @@ -205,24 +239,43 @@ var Kanai;
return elem.isStashed() && !(elem.isCubedNonSeason() || elem.isCubedSeason());
}).length;
});
this.ArmorBothCubedCount = ko.computed(function () {
return ko.utils.arrayFilter(self.Armor(), function (item) {
var elem = ko.unwrap(item);
return elem.isCubedNonSeason() || elem.isCubedSeason();
}).length;
});
this.WeaponBothCubedCount = ko.computed(function () {
return ko.utils.arrayFilter(self.Weapons(), function (item) {
var elem = ko.unwrap(item);
return elem.isCubedNonSeason() || elem.isCubedSeason();
}).length;
});
this.JewelryBothCubedCount = ko.computed(function () {
return ko.utils.arrayFilter(self.Jewelry(), function (item) {
var elem = ko.unwrap(item);
return elem.isCubedNonSeason() || elem.isCubedSeason();
}).length;
});
this.StashedCount = ko.computed(function () {
return _this.JewelryStashedCount() + _this.WeaponStashedCount() + _this.ArmorStashedCount();
});
this.hideCubed.subscribe(function () { self.saveToLocalStorage(); });
this.hideCubedNonSeason.subscribe(function () { self.saveToLocalStorage(); });
this.nonSeasonalProgressBar.subscribe(function () { self.saveToLocalStorage(); });
this.seasonalProgressBar.subscribe(function () { self.saveToLocalStorage(); });
this.bothProgressBar.subscribe(function () { self.saveToLocalStorage(); });
};
Site.prototype.fillExport = function () {
var self = this;
this.Export(ko.mapping.toJSON(self));
};
Site.prototype.saveToLocalStorage = function () {
var self = this;
localStorage["kanai_cube"] = null;
localStorage[self.localStorageString] = null;
delete this.Jewelery;
localStorage.setItem("kanai_cube", ko.mapping.toJSON(self, {
"ignore": ["AllWeapons", "AllJewelry", "Export", "AllArmor", "ArmorNonSeasonalCubedCount", "ArmorSeasonalCubedCount", "ArmorStashedCount", "JewelryNonSeasonalCubedCount", "JewelrySeasonalCubedCount", "JewelryStashedCount", "StashedCount", "WeaponNonSeasonalCubedCount", "WeaponSeasonalCubedCount", "WeaponStashedCount"] }));
localStorage.setItem(self.localStorageString, ko.mapping.toJSON(self, {
"ignore": ["AllWeapons", "AllJewelry", "FilteredArray", "Search", "Export", "AllArmor", "ArmorNonSeasonalCubedCount", "ArmorSeasonalCubedCount", "ArmorStashedCount", "JewelryNonSeasonalCubedCount", "JewelrySeasonalCubedCount", "JewelryStashedCount", "StashedCount", "WeaponNonSeasonalCubedCount", "WeaponSeasonalCubedCount", "WeaponStashedCount", "ArmorBothCubedCount", "WeaponBothCubedCount", "JewelryBothCubedCount"] }));
};
// This function will return correct spelling of words that I typoed at some time without destroying user data or duplicating records
Site.prototype.spellcheckCorrect = function (searchName) {
Expand Down
80 changes: 72 additions & 8 deletions tscripts/VM/items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
/// <reference path="../jquery.d.ts"/>
/// <reference path="../models/equipment.ts"/>
/// <reference path="../lang.ts" />

/// <reference path="../includes.d.ts"/>
module Kanai {
export module VM {
export class Site {
localStorageString:string = "kanai_cube";
Weapons: KnockoutObservableArray<KnockoutObservable<Equipment>>;
Jewelry: KnockoutObservableArray<KnockoutObservable<Equipment>>;
Jewelery: KnockoutObservableArray<KnockoutObservable<Equipment>>;
Expand All @@ -27,6 +28,11 @@ module Kanai {
WeaponNonSeasonalCubedCount: KnockoutComputed<number>;
JewelryNonSeasonalCubedCount: KnockoutComputed<number>;

//both
bothProgressBar: KnockoutObservable<boolean>;
ArmorBothCubedCount: KnockoutComputed<number>;
WeaponBothCubedCount: KnockoutComputed<number>;
JewelryBothCubedCount: KnockoutComputed<number>;
ArmorStashedCount: KnockoutComputed<number>;
WeaponStashedCount: KnockoutComputed<number>;
JewelryStashedCount: KnockoutComputed<number>;
Expand All @@ -40,6 +46,9 @@ module Kanai {
AllJewelery: Equipment[];
AllArmor: Equipment[];

Search: KnockoutObservable<string>;
FilteredArray:KnockoutObservableArray<KnockoutObservable<Equipment>>;

constructor() {
var self = this;
this.Weapons = ko.observableArray<KnockoutObservable<Equipment>>();
Expand All @@ -51,20 +60,53 @@ module Kanai {
this.hideNonSeasonalCheckboxes = ko.observable(false).extend({ notify: 'always' });
this.hideSeasonalCheckboxes = ko.observable(false).extend({ notify: 'always' });
this.seasonalProgressBar = ko.observable(true).extend({ notify: 'always' });
this.bothProgressBar = ko.observable(false).extend({ notify: 'always' });
this.AllWeapons = new Array<Equipment>();
this.AllJewelry = new Array<Equipment>();
this.AllArmor = new Array<Equipment>();
this.Export = ko.observable<string>();
this.Import = ko.observable<string>();
this.Search = ko.observable<string>('').extend({ notify: 'always', rateLimit: 200 });
this.FilteredArray = ko.observableArray<KnockoutObservable<Equipment>>([]);
this.Search.subscribe((searchText) => {
if (searchText && searchText.length >= 2) {
//we need to search the array
self.FilteredArray([]);
self.searchArray(self.Armor, searchText, self.FilteredArray);
self.searchArray(self.Weapons, searchText, self.FilteredArray);
self.searchArray(self.Jewelry, searchText, self.FilteredArray);
if (self.FilteredArray().length > 0) {
self.FilteredArray.valueHasMutated();
$("a[href='#panel-search']").tab("show");
}
} else {
$("a[href='#panel-armor']").tab("show");
self.FilteredArray([]);
$(".sticky").removeClass('sticky');
$(".sticky-progress").removeClass("sticky-progress");
$(".sticky-table").removeClass('sticky-table');
}
});
}

searchArray(array: KnockoutObservableArray<KnockoutObservable<Equipment>>, searchText: string, response:KnockoutObservableArray<KnockoutObservable<Equipment>>):boolean {
var res = ko.utils.arrayFilter(array(), (item: any) => {
var lowerItemName = ko.unwrap(item.itemName).toString().toLowerCase();
var lowerAffix = ko.unwrap(item.affix).toString().toLowerCase();
return (lowerItemName.indexOf(searchText) !== -1) || (lowerAffix.indexOf(searchText) !== -1);
});
ko.utils.arrayPushAll(response(), res);
return res.length > 0;
}

clear() {
this.Weapons([]);
this.Jewelry([]);
this.Armor([]);
}
init() {
var self = this;
var vm = JSON.parse(localStorage.getItem("kanai_cube"));
var vm = JSON.parse(localStorage.getItem(self.localStorageString));
if (!vm) {
this.loadWeapons(self.Weapons);
this.loadJewelry(self.Jewelry);
Expand All @@ -83,7 +125,7 @@ module Kanai {
this.Jewelry.sort(function (left, right) {
return left().itemName() == right().itemName() ? 0 : (left().itemName() < right().itemName() ? -1 : 1);
});
localStorage.setItem("kanai_cube", ko.mapping.toJSON(this));
localStorage.setItem(self.localStorageString, ko.mapping.toJSON(this));

$.each(self.Armor(), function (i, elem: KnockoutObservable<Equipment>) {
elem().isCubedSeason.subscribe((newValue) => {
Expand Down Expand Up @@ -137,7 +179,7 @@ module Kanai {
self.Jewelry = ko.observableArray<KnockoutObservable<Equipment>>();
}
}
ko.mapping.fromJS(vm, { "include": ["hideCubed", "hideCubedNonSeason", "nonSeasonalProgressBar", "seasonalProgressBar"]}, self);
ko.mapping.fromJS(vm, { "include": ["hideCubed", "hideCubedNonSeason", "nonSeasonalProgressBar", "seasonalProgressBar", "bothProgressBar"]}, self);
this.checkConsistency();
this.saveToLocalStorage();
$.each(self.Armor(), function (i, elem: Equipment) {
Expand Down Expand Up @@ -254,6 +296,27 @@ module Kanai {
}).length;
});

this.ArmorBothCubedCount = ko.computed(() => {
return ko.utils.arrayFilter(self.Armor(), (item: Equipment) => {
var elem = ko.unwrap(item);
return elem.isCubedNonSeason() || elem.isCubedSeason();
}).length;
});

this.WeaponBothCubedCount = ko.computed(() => {
return ko.utils.arrayFilter(self.Weapons(), (item: Equipment) => {
var elem = ko.unwrap(item);
return elem.isCubedNonSeason() || elem.isCubedSeason();
}).length;
});

this.JewelryBothCubedCount = ko.computed(() => {
return ko.utils.arrayFilter(self.Jewelry(), (item: Equipment) => {
var elem = ko.unwrap(item);
return elem.isCubedNonSeason() || elem.isCubedSeason();
}).length;
});

this.StashedCount = ko.computed(() => {
return this.JewelryStashedCount() + this.WeaponStashedCount() + this.ArmorStashedCount();
});
Expand All @@ -262,6 +325,7 @@ module Kanai {
this.hideCubedNonSeason.subscribe(() => { self.saveToLocalStorage(); });
this.nonSeasonalProgressBar.subscribe(() => { self.saveToLocalStorage(); });
this.seasonalProgressBar.subscribe(() => { self.saveToLocalStorage(); });
this.bothProgressBar.subscribe(() => { self.saveToLocalStorage(); });
}

fillExport() {
Expand All @@ -271,12 +335,12 @@ module Kanai {

saveToLocalStorage() {
var self = this;
localStorage["kanai_cube"] = null;
localStorage[self.localStorageString] = null;
delete this.Jewelery;
localStorage.setItem("kanai_cube", ko.mapping.toJSON(self, {
"ignore": ["AllWeapons", "AllJewelry", "Export", "AllArmor", "ArmorNonSeasonalCubedCount", "ArmorSeasonalCubedCount", "ArmorStashedCount", "JewelryNonSeasonalCubedCount", "JewelrySeasonalCubedCount", "JewelryStashedCount", "StashedCount", "WeaponNonSeasonalCubedCount", "WeaponSeasonalCubedCount", "WeaponStashedCount"]}));
localStorage.setItem(self.localStorageString, ko.mapping.toJSON(self, {
"ignore": ["AllWeapons", "AllJewelry", "FilteredArray", "Search", "Export", "AllArmor", "ArmorNonSeasonalCubedCount", "ArmorSeasonalCubedCount", "ArmorStashedCount", "JewelryNonSeasonalCubedCount", "JewelrySeasonalCubedCount", "JewelryStashedCount", "StashedCount", "WeaponNonSeasonalCubedCount", "WeaponSeasonalCubedCount", "WeaponStashedCount", "ArmorBothCubedCount", "WeaponBothCubedCount", "JewelryBothCubedCount"]}));
}

// This function will return correct spelling of words that I typoed at some time without destroying user data or duplicating records
spellcheckCorrect(searchName: string) {
switch (searchName) {
Expand Down
3 changes: 3 additions & 0 deletions tscripts/includes.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
interface JQuery {
tab(options?:any):any;
}
Loading

0 comments on commit 83da068

Please sign in to comment.