<commit_before>﻿import * as React from 'react'
import { Button } from 'react-bootstrap'
import * as numbro from 'numbro'
import { classes } from '../../../../Framework/Signum.React/Scripts/Globals'
import * as Finder from '../../../../Framework/Signum.React/Scripts/Finder'
import * as Navigator from '../../../../Framework/Signum.React/Scripts/Navigator'
import { TypeEntity } from '../../../../Framework/Signum.React/Scripts/Signum.Entities.Basics'
import { notifySuccess }from '../../../../Framework/Signum.React/Scripts/Operations/EntityOperations'
import EntityLink from '../../../../Framework/Signum.React/Scripts/SearchControl/EntityLink'
import { TypeContext, ButtonsContext, IRenderButtons, EntityFrame } from '../../../../Framework/Signum.React/Scripts/TypeContext'
import { EntityLine, ValueLine } from '../../../../Framework/Signum.React/Scripts/Lines'
import SelectorModal from '../../../../Framework/Signum.React/Scripts/SelectorModal'
import MessageModal from '../../../../Framework/Signum.React/Scripts/Modals/MessageModal'

import { QueryDescription, SubTokensOptions } from '../../../../Framework/Signum.React/Scripts/FindOptions'
import { getQueryNiceName, PropertyRoute, getTypeInfo, Binding, GraphExplorer } from '../../../../Framework/Signum.React/Scripts/Reflection'
import { ModifiableEntity, EntityControlMessage, Entity, parseLite, getToString, JavascriptMessage } from '../../../../Framework/Signum.React/Scripts/Signum.Entities'
import { Api, properties, queries, operations } from '../AuthClient'
import {
    TypeRulePack, AuthAdminMessage, PermissionSymbol, AuthMessage, TypeAllowed, TypeAllowedRule,
    TypeAllowedAndConditions, TypeAllowedBasic, TypeConditionRuleEmbedded, AuthThumbnail, PropertyRulePack, OperationRulePack, QueryRulePack, RoleEntity
} from '../Signum.Entities.Authorization'
import { ColorRadio, GrayCheckbox } from './ColoredRadios'
import { TypeConditionSymbol } from '../../Basics/Signum.Entities.Basics'
import { OperationSymbol, ModelEntity } from '../../../../Framework/Signum.React/Scripts/Signum.Entities'
import { QueryEntity, PropertyRouteEntity } from '../../../../Framework/Signum.React/Scripts/Signum.Entities.Basics'
import { NormalControlMessage } from "../../../../Framework/Signum.React/Scripts/Signum.Entities";


require("./AuthAdmin.css");

export default class TypesRulesPackControl extends React.Component<{ ctx: TypeContext<TypeRulePack>, frame: EntityFrame<TypeRulePack> }, { filter: string }> implements IRenderButtons {

    state = { filter: "" };

    handleSaveClick = (bc: ButtonsContext) => {
        let pack = this.props.ctx.value;

        Api.saveTypeRulePack(pack)
            .then(() => Api.fetchTypeRulePack(pack.role.id!))
            .then(newPack => {
                notifySuccess();
                bc.frame.onReload({ entity: newPack, canExecute: {} });
            })
            .done();
    }

    handleResetChangesClick = (bc: ButtonsContext) => {
        let pack = this.props.ctx.value;

        Api.fetchTypeRulePack(pack.role.id!)
            .then(newPack => {
                bc.frame.onReload({ entity: newPack, canExecute: {} });
            })
            .done();
    }

    handleSwitchToClick = (bc: ButtonsContext) => {
        let pack = this.props.ctx.value;

        Finder.find(RoleEntity).then(r => {
            if (!r)
                return;

            Api.fetchTypeRulePack(r.id!)
                .then(newPack => bc.frame.onReload({ entity: newPack, canExecute: {} }))
                .done();
        });
    }

    updateFrame() {
        this.props.frame.frameComponent.forceUpdate();
    }

    renderButtons(bc: ButtonsContext) {

        GraphExplorer.propagateAll(bc.pack.entity);
        
        const hasChanges = bc.pack.entity.modified;

        return [
            <Button bsStyle="primary" disabled={!hasChanges} onClick={() => this.handleSaveClick(bc)}>{AuthMessage.Save.niceToString()}</Button>,
            <Button bsStyle="warning" disabled={!hasChanges} onClick={() => this.handleResetChangesClick(bc)}>{AuthAdminMessage.ResetChanges.niceToString()}</Button>,
            <Button bsStyle="info" disabled={hasChanges} onClick={() => this.handleSwitchToClick(bc)}>{AuthAdminMessage.SwitchTo.niceToString()}</Button>
        ];
    }
<commit_msg>remove props.frame: EntityFrame<TypeRulePack> and use ctx.frame<commit_after>﻿import * as React from 'react'
import { Button } from 'react-bootstrap'
import * as numbro from 'numbro'
import { classes } from '../../../../Framework/Signum.React/Scripts/Globals'
import * as Finder from '../../../../Framework/Signum.React/Scripts/Finder'
import * as Navigator from '../../../../Framework/Signum.React/Scripts/Navigator'
import { TypeEntity } from '../../../../Framework/Signum.React/Scripts/Signum.Entities.Basics'
import { notifySuccess }from '../../../../Framework/Signum.React/Scripts/Operations/EntityOperations'
import EntityLink from '../../../../Framework/Signum.React/Scripts/SearchControl/EntityLink'
import { TypeContext, ButtonsContext, IRenderButtons, EntityFrame } from '../../../../Framework/Signum.React/Scripts/TypeContext'
import { EntityLine, ValueLine } from '../../../../Framework/Signum.React/Scripts/Lines'
import SelectorModal from '../../../../Framework/Signum.React/Scripts/SelectorModal'
import MessageModal from '../../../../Framework/Signum.React/Scripts/Modals/MessageModal'

import { QueryDescription, SubTokensOptions } from '../../../../Framework/Signum.React/Scripts/FindOptions'
import { getQueryNiceName, PropertyRoute, getTypeInfo, Binding, GraphExplorer } from '../../../../Framework/Signum.React/Scripts/Reflection'
import { ModifiableEntity, EntityControlMessage, Entity, parseLite, getToString, JavascriptMessage } from '../../../../Framework/Signum.React/Scripts/Signum.Entities'
import { Api, properties, queries, operations } from '../AuthClient'
import {
    TypeRulePack, AuthAdminMessage, PermissionSymbol, AuthMessage, TypeAllowed, TypeAllowedRule,
    TypeAllowedAndConditions, TypeAllowedBasic, TypeConditionRuleEmbedded, AuthThumbnail, PropertyRulePack, OperationRulePack, QueryRulePack, RoleEntity
} from '../Signum.Entities.Authorization'
import { ColorRadio, GrayCheckbox } from './ColoredRadios'
import { TypeConditionSymbol } from '../../Basics/Signum.Entities.Basics'
import { OperationSymbol, ModelEntity } from '../../../../Framework/Signum.React/Scripts/Signum.Entities'
import { QueryEntity, PropertyRouteEntity } from '../../../../Framework/Signum.React/Scripts/Signum.Entities.Basics'
import { NormalControlMessage } from "../../../../Framework/Signum.React/Scripts/Signum.Entities";


require("./AuthAdmin.css");

export default class TypesRulesPackControl extends React.Component<{ ctx: TypeContext<TypeRulePack> }, { filter: string }> implements IRenderButtons {

    state = { filter: "" };

    handleSaveClick = (bc: ButtonsContext) => {
        let pack = this.props.ctx.value;

        Api.saveTypeRulePack(pack)
            .then(() => Api.fetchTypeRulePack(pack.role.id!))
            .then(newPack => {
                notifySuccess();
                bc.frame.onReload({ entity: newPack, canExecute: {} });
            })
            .done();
    }

    handleResetChangesClick = (bc: ButtonsContext) => {
        let pack = this.props.ctx.value;

        Api.fetchTypeRulePack(pack.role.id!)
            .then(newPack => {
                bc.frame.onReload({ entity: newPack, canExecute: {} });
            })
            .done();
    }

    handleSwitchToClick = (bc: ButtonsContext) => {
        let pack = this.props.ctx.value;

        Finder.find(RoleEntity).then(r => {
            if (!r)
                return;

            Api.fetchTypeRulePack(r.id!)
                .then(newPack => bc.frame.onReload({ entity: newPack, canExecute: {} }))
                .done();
        });
    }

    updateFrame() {
        this.props.ctx.frame!.frameComponent.forceUpdate();
    }

    renderButtons(bc: ButtonsContext) {

        GraphExplorer.propagateAll(bc.pack.entity);
        
        const hasChanges = bc.pack.entity.modified;

        return [
            <Button bsStyle="primary" disabled={!hasChanges} onClick={() => this.handleSaveClick(bc)}>{AuthMessage.Save.niceToString()}</Button>,
            <Button bsStyle="warning" disabled={!hasChanges} onClick={() => this.handleResetChangesClick(bc)}>{AuthAdminMessage.ResetChanges.niceToString()}</Button>,
            <Button bsStyle="info" disabled={hasChanges} onClick={() => this.handleSwitchToClick(bc)}>{AuthAdminMessage.SwitchTo.niceToString()}</Button>
        ];
    }

{'fraction_non_alphanumeric': 0.16381816067899083, 'fraction_numerical': 0.0, 'mean_word_length': 3.048, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '138912', 'n_tokens_mistral': 2363, 'n_tokens_neox': 2419, 'n_words': 435}