private void BuildBlacklistTable() { _blacklistTable = new FlareTable <Infrastructure.Schema.Blacklist>( BlacklistModel.List, monospace: true ); _blacklistTable.RegisterColumn(nameof(Infrastructure.Schema.Blacklist.ID), width: "80px"); _blacklistTable.RegisterColumn(nameof(Infrastructure.Schema.Blacklist.Pattern)); _blacklistTable.RegisterColumn(nameof(Infrastructure.Schema.Blacklist.Expires)); _blacklistTable.RegisterColumn("_Remove", sortable: false, filterable: false, displayName: "", width: "82px"); _loaded = true; InvokeAsync(StateHasChanged); }
protected override void OnInitialized() { _clientRole = Utility.GetRole(AuthenticationStateTask ?? throw new ArgumentNullException()).Result; _newRule = new Infrastructure.Schema.Whitelist(); if (_clientRole != UserRole.Roles.Privileged && _clientRole != UserRole.Roles.Administrator) { throw new Exception(); } Log?fromLog = LogActionService.GetAndUnset(); if (fromLog != null) { Console.WriteLine("From log: " + fromLog.Question); string pattern = @"(?:^|.+\.)" + fromLog.Question.Replace(".", @"\.") + "$"; Rule().Pattern = pattern; } InitValidators(); InitInputs(); // _whitelistTable = new FlareTable <Infrastructure.Schema.Whitelist>( () => _clientRole == UserRole.Roles.Privileged ? WhitelistModel.List(ClientIP !) : WhitelistModel.List(), sessionStorage: SessionStorageService, identifier: "Rules.WhitelistTable", monospace: true); _whitelistTable.RegisterColumn(nameof(Infrastructure.Schema.Whitelist.ID)); _whitelistTable.RegisterColumn(nameof(Infrastructure.Schema.Whitelist.Pattern)); _whitelistTable.RegisterColumn(nameof(Infrastructure.Schema.Whitelist.Expires)); _whitelistTable.RegisterColumn("_Edit", sortable: false, filterable: false, displayName: "", width: "56px"); _whitelistTable.RegisterColumn("_Remove", sortable: false, filterable: false, displayName: "", width: "82px"); _whitelistTable.OnRowClick += whitelist => { }; BuildHeaders(); }
protected override void OnInitialized() { _dummyFlareTable = new FlareTable <Record>(() => RecordCache.Records); _flareTable1 = new FlareTable <Record>( () => RecordCache.Records, new SessionStorageProvider(SessionStorage), // new LocalStorageProvider(LocalStorage), "ft3x", fixedLayout: true, rowColorGetter: row => row.Zip.StartsWith("0") || row.Name.StartsWith("A") ? RowColor.Undefined : row.Zip.Contains("-") ? RowColor.Red : RowColor.Green, clickable: true ); _flareTable1.RegisterColumn(nameof(Record.Name), shown: true, sortDirection: SortDirections.Ascending); _flareTable1.RegisterColumn(nameof(Record.Age), filterValue: "1", width: "60px"); _flareTable1.RegisterColumn(nameof(Record.City), filterable: false, sortable: false); _flareTable1.RegisterColumn(nameof(Record.State), sortable: false); _flareTable1.RegisterColumn(nameof(Record.Country), shown: false, filterable: false, displayName: ""); _flareTable1.RegisterColumn(nameof(Record.Zip), shown: false, monospace: true, width: "120px"); _flareTable1.OnRowClick += record => Console.WriteLine($"Click: {record.Name}"); _flareTable1.OnRowClickDetail += (record, ctrl, shift, mid) => Console.WriteLine($"Click detail: {record.Name} | Ctrl: {ctrl} | Shift: {shift} | Mid: {mid}"); }
protected override void OnInitialized() { LoadUsers(); _user = ((ContraWebAuthStateProvider)ContraWebAuthStateProvider).User; if (_user == null) { throw new Exception("User is not authenticated; access to this page should not have been permitted."); } _userTable = new FlareTable <User>( () => _users ?? new List <User>()); _userTable.RegisterColumn(nameof(User.Username)); _userTable.RegisterColumn(nameof(User.Role)); _userTable.RegisterColumn("_Edit", sortable: false, filterable: false, displayName: "", width: "56px"); _userTable.RegisterColumn("_Remove", sortable: false, filterable: false, displayName: "", width: "82px"); // _newUsernameDebouncer = new Debouncer <string>(value => { Console.WriteLine("--"); _newUsername = value; _newUserValidator.Validate(); InvokeAsync(StateHasChanged); }, _newUsername); _newPasswordDebouncer = new Debouncer <string>(value => { _newPassword = value; _newUserValidator.Validate(); InvokeAsync(StateHasChanged); }, _newPassword); // _newRoleSelector = new FlareSelector <string>( () => UserRole.Options(), false ); _newRoleSelector.OnSelect += selected => { _newRole = UserRole.NameToUserRole(selected.FirstOrDefault()?.ID); _newUserValidator.Validate(); InvokeAsync(StateHasChanged); }; _editedRoleSelector = new FlareSelector <string>( () => UserRole.Options(_editing?.Role), false, isDisabled: () => _editing?.Username == _user.Username); _editedRoleSelector.OnSelect += selected => { _editedRole = UserRole.NameToUserRole(selected.FirstOrDefault()?.ID); _editUserValidator.Validate(); InvokeAsync(StateHasChanged); }; // _newMACsSelector = new EditableList( validator: ValidateMAC, placeholder: "Add a MAC", transformer: Utility.FormatMAC ); _newMACsSelector.OnUpdate += macs => _user !.MACs = macs.Select(v => PhysicalAddress.Parse(Utility.CleanMAC(v))).ToList(); _editMACsSelector = new EditableList( validator: ValidateMAC, placeholder: "Add a MAC", transformer: Utility.FormatMAC ); _editMACsSelector.OnUpdate += macs => _editing !.MACs = macs.Select(v => PhysicalAddress.Parse(Utility.CleanMAC(v))).ToList(); // _newUserValidator = new Validator <ValidationResult>(() => { if (string.IsNullOrEmpty(_newUsername)) { return new[] { new Validation <ValidationResult>(ValidationResult.Invalid, "Username is required") } } ; User?found = UserModel.Find(_newUsername).Result; if (found != null) { return new[] { new Validation <ValidationResult>(ValidationResult.Invalid, "Username is already registered") } } ; if (string.IsNullOrEmpty(_newPassword)) { return new[] { new Validation <ValidationResult>(ValidationResult.Invalid, "Password is required") } } ; if (_newRole == UserRole.Roles.Undefined || _newRole == UserRole.Roles.Restricted) { return new[] { new Validation <ValidationResult>(ValidationResult.Invalid, "Role is invalid") } } ; return(new[] { new Validation <ValidationResult>(ValidationResult.Valid, "User is valid") }); }); _editUserValidator = new Validator <ValidationResult>(() => { // if (string.IsNullOrEmpty(_editedPassword)) // return new Validation(ValidationResult.Invalid, "Password is required"); if (_editedRole == UserRole.Roles.Undefined || _editedRole == UserRole.Roles.Restricted) { return new[] { new Validation <ValidationResult>(ValidationResult.Invalid, "Role is invalid") } } ; return(new[] { new Validation <ValidationResult>(ValidationResult.Valid, "Edits are valid") }); }); _newUserValidator.Validate(); // BuildHeaders(); }