code:
:: assignment-filter widget [widget nobr]

/*
 * filters the list according to the selected Facility
 * function(y) is a loop through $slaves to set assignmentVisible to 1 and returns a new array
 * function(x) filters the slaves with the given condition ( here its the assignment )
 * so basically function(x) finds the slaves that are selected and function(y) sets them to be visible
*/

/*
 * These widgets set the visibilities for the different Facilities
*/

<<widget "resetAssignmentFilter">>
	<<set $slaves.map(function(y){y.assignmentVisible = 1})>><<set $slaves.filter(function(x){return x.assignment.includes("in the") || x.assignment.includes("be the") || x.assignment.includes("live with") || (x.assignment.includes("be your") && x.assignment != "be your Head Girl") || x.assignment.includes("work as a ")}).map(function(y){y.assignmentVisible = 0})>>
<</widget>>

<<widget "showallAssignmentFilter">>
	<<set $slaves.map(function(y){y.assignmentVisible = 1})>><<set $slaves.filter(function(x){return x.assignment.includes("agent")}).map(function(y){y.assignmentVisible = 0})>>
<</widget>>

<<widget "arcadeAssignmentFilter">>
	<<set $slaves.map(function(y){y.assignmentVisible = 0})>><<set $slaves.filter(function(x){return x.assignment == "be confined in the arcade"}).map(function(y){y.assignmentVisible = 1})>>
<</widget>>

<<widget "brothelAssignmentFilter">>
	<<set $slaves.map(function(y){y.assignmentVisible = 0})>><<set $slaves.filter(function(x){return x.assignment == "work in the brothel" || x.assignment == "be the Madam"}).map(function(y){y.assignmentVisible = 1})>>
<</widget>>

<<widget "cellblockAssignmentFilter">>
	<<set $slaves.map(function(y){y.assignmentVisible = 0})>><<set $slaves.filter(function(x){return x.assignment == "be confined in the cellblock" || x.assignment == "be the Wardeness"}).map(function(y){y.assignmentVisible = 1})>>
<</widget>>

<<widget "clinicAssignmentFilter">>
	<<set $slaves.map(function(y){y.assignmentVisible = 0})>><<set $slaves.filter(function(x){return x.assignment == "get treatment in the clinic" || x.assignment == "be the Nurse"}).map(function(y){y.assignmentVisible = 1})>>
<</widget>>

<<widget "clubAssignmentFilter">>
	<<set $slaves.map(function(y){y.assignmentVisible = 0})>><<set $slaves.filter(function(x){return x.assignment == "serve in the club" || x.assignment == "be the DJ"}).map(function(y){y.assignmentVisible = 1})>>
<</widget>>

<<widget "dairyAssignmentFilter">>
	<<set $slaves.map(function(y){y.assignmentVisible = 0})>><<set $slaves.filter(function(x){return x.assignment == "work in the dairy" || x.assignment == "be the Milkmaid"}).map(function(y){y.assignmentVisible = 1})>>
<</widget>>

<<widget "farmyardAssignmentFilter">>
		<<set $slaves.map(function(y){y.assignmentVisible = 0})>><<set $slaves.filter(function(x){return x.assignment == "work as a farmhand"  || x.assignment == "be the Farmer"}).map(function(y){y.assignmentVisible = 1})>>
<</widget>>

<<widget "headgirlSuiteAssignmentFilter">>
	<<set $slaves.map(function(y){y.assignmentVisible = 0})>><<set $slaves.filter(function(x){return x.assignment == "live with your Head Girl"}).map(function(y){y.assignmentVisible = 1})>>
<</widget>>

<<widget "penthouseAssignmentFilter">>
	<<set $slaves.map(function(y){y.assignmentVisible = 0})>><<set $slaves.filter(function(x){return x.assignment == "rest" || x.assignment == "be a subordinate slave" || x.assignment == "whore" || x.assignment == "serve the public" || x.assignment == "work a glory hole" || x.assignment == "get milked" || x.assignment == "be a servant" || x.assignment == "please you"|| x.assignment == "stay confined" || x.assignment == "take classes" || x.assignment == "choose her own job" || x.assignment == "live with your Head Girl"}).map(function(y){y.assignmentVisible = 1})>>
<</widget>>

<<widget "schoolAssignmentFilter">>
	<<set $slaves.map(function(y){y.assignmentVisible = 0})>><<set $slaves.filter(function(x){return x.assignment == "learn in the schoolroom" || x.assignment == "be the Schoolteacher"}).map(function(y){y.assignmentVisible = 1})>>
<</widget>>

<<widget "spaAssignmentFilter">>
	<<set $slaves.map(function(y){y.assignmentVisible = 0})>><<set $slaves.filter(function(x){return x.assignment == "rest in the spa" || x.assignment == "be the Attendant"}).map(function(y){y.assignmentVisible = 1})>>
<</widget>>

<<widget "nurseryAssignmentFilter">>
	<<set $slaves.map(function(y){y.assignmentVisible = 0})>><<set $slaves.filter(function(x){return x.assignment == "work as a nanny" || x.assignment == "be the Matron"}).map(function(y){y.assignmentVisible = 1})>>
<</widget>>

<<widget "suiteAssignmentFilter">>
	<<set $slaves.map(function(y){y.assignmentVisible = 0})>><<set $slaves.filter(function(x){return x.assignment == "serve in the master suite" || x.assignment == "be your Concubine"}).map(function(y){y.assignmentVisible = 1})>>
<</widget>>

<<widget "quartersAssignmentFilter">>
	<<set $slaves.map(function(y){y.assignmentVisible = 0})>><<set $slaves.filter(function(x){return x.assignment == "work as a servant" || x.assignment == "be the Stewardess"}).map(function(y){y.assignmentVisible = 1})>>
<</widget>>

/*
 * Checks from which Facility its get called and removes it from the list
 * this is the Main Filter widget used on all Passages atm
 * sets Flag = zero so slave summary provides send-to-facility links
*/
<<widget "assignmentFilter">>
	<<link All>><<showallAssignmentFilter>><<replace #ComingGoing>><<set $Flag = 0>><<include 'Slave Summary'>><<resetAssignmentFilter>><</replace>><</link>>
	<<if passage() != "Arcade">><<print " | ">><<link Arcade>><<arcadeAssignmentFilter>><<replace #ComingGoing>><<set $Flag = 0>><<include 'Slave Summary'>><<resetAssignmentFilter>><</replace>><</link>><</if>>
	<<if passage() != "Brothel">><<print " | ">><<link Brothel>><<brothelAssignmentFilter>><<replace #ComingGoing>><<set $Flag = 0>><<include 'Slave Summary'>><<resetAssignmentFilter>><</replace>><</link>><</if>>
	<<if passage() != "Cellblock">><<print " | ">><<link Cellblock>><<cellblockAssignmentFilter>><<replace #ComingGoing>><<set $Flag = 0>><<include 'Slave Summary'>><<resetAssignmentFilter>><</replace>><</link>><</if>>
	<<if passage() != "Clinic">><<print " | ">><<link Clinic>><<clinicAssignmentFilter>><<replace #ComingGoing>><<set $Flag = 0>><<include 'Slave Summary'>><<resetAssignmentFilter>><</replace>><</link>><</if>>
	<<if passage() != "Club">><<print " | ">><<link Club>><<clubAssignmentFilter>><<replace #ComingGoing>><<set $Flag = 0>><<include 'Slave Summary'>><<resetAssignmentFilter>><</replace>><</link>><</if>>
	<<if passage() != "Dairy">><<print " | ">><<link Dairy>><<dairyAssignmentFilter>><<replace #ComingGoing>><<set $Flag = 0>><<include 'Slave Summary'>><<resetAssignmentFilter>><</replace>><</link>><</if>>
	<<if passage() != "Farmyard">><<print " | ">><<link Farmyard>><<farmyardAssignmentFilter>><<replace #ComingGoing>><<set $Flag = 0>><<include 'Slave Summary'>><<resetAssignmentFilter>><</replace>><</link>><</if>>
	<<print " | ">><<link Penthouse>><<penthouseAssignmentFilter>><<replace #ComingGoing>><<include 'Slave Summary'>><<set $Flag = 0>><<resetAssignmentFilter>><</replace>><</link>>
	<<if passage() != "Schoolroom">><<print " | ">><<link Schoolroom>><<schoolAssignmentFilter>><<replace #ComingGoing>><<set $Flag = 0>><<include 'Slave Summary'>><<resetAssignmentFilter>><</replace>><</link>><</if>>
	<<if passage() != "Spa">><<print " | ">><<link Spa>><<spaAssignmentFilter>><<replace #ComingGoing>><<set $Flag = 0>><<include 'Slave Summary'>><<resetAssignmentFilter>><</replace>><</link>><</if>>
	<<if passage() != "Nursery">><<print " | ">><<link Nursery>><<nurseryAssignmentFilter>><<replace #ComingGoing>><<set $Flag = 0>><<include 'Slave Summary'>><<resetAssignmentFilter>><</replace>><</link>><</if>>
	<<if passage() != "Master Suite">><<print " | ">><<link Suite>><<suiteAssignmentFilter>><<replace #ComingGoing>><<set $Flag = 0>><<include 'Slave Summary'>><<resetAssignmentFilter>><</replace>><</link>><</if>>
	<<if passage() != "Servants' Quarters">><<print " | ">><<link Quarters>><<quartersAssignmentFilter>><<set $Flag = 0>><<replace #ComingGoing>><<include 'Slave Summary'>><<resetAssignmentFilter>><</replace>><</link>><</if>>
<</widget>>

/*
 * undefinedAssignmentFilter serves no purpose atm
 * might use it for RA Slave filter and Matchmaking
*/
<<widget "undefinedAssignmentFilter">>
	<<link All>><<showallAssignmentFilter>><<replace $args.full>><<include 'Slave Summary'>><</replace>><</link>><<print " | ">>
	<<link Arcade>><<arcadeAssignmentFilter>><<replace $args.full>><<include 'Slave Summary'>><</replace>><</link>><<print " | ">>
	<<link Brothel>><<brothelAssignmentFilter>><<replace $args.full>><<include 'Slave Summary'>><</replace>><</link>><<print " | ">>
	<<link Cellblock>><<cellblockAssignmentFilter>><<replace $args.full>><<include 'Slave Summary'>><</replace>><</link>><<print " | ">>
	<<link Clinic>><<clinicAssignmentFilter>><<replace $args.full>><<include 'Slave Summary'>><</replace>><</link>><<print " | ">>
	<<link Club>><<clubAssignmentFilter>><<replace $args.full>><<include 'Slave Summary'>><</replace>><</link>><<print " | ">>
	<<link Dairy>><<dairyAssignmentFilter>><<replace $args.full>><<include 'Slave Summary'>><</replace>><</link>><<print " | ">>
	<<link Farmyard>><<farmyardAssignmentFilter>><<replace $args.full>><<include 'Slave Summary'>><</replace>><</link>><<print " | ">>
	<<link Penthouse>><<penthouseAssignmentFilter>><<replace $args.full>><<include 'Slave Summary'>><</replace>><</link>><<print " | ">>
	<<link Schoolroom>><<schoolAssignmentFilter>><<replace $args.full>><<include 'Slave Summary'>><</replace>><</link>><<print " | ">>
	<<link Spa>><<spaAssignmentFilter>><<replace $args.full>><<include 'Slave Summary'>><</replace>><</link>><<print " | ">>
	<<link Nursery>><<nurseryAssignmentFilter>><<replace $args.full>><<include 'Slave Summary'>><</replace>><</link>><<print " | ">>
	<<link Suite>><<suiteAssignmentFilter>><<replace $args.full>><<include 'Slave Summary'>><</replace>><</link>><<print " | ">>
	<<link Quarters>><<quartersAssignmentFilter>><<replace $args.full>><<include 'Slave Summary'>><</replace>><</link>>
	<<resetAssignmentFilter>>
<</widget>>