angularjs directive in ag-grid's IHeaderComponent? - ag-grid

Is there a way to add your own directive to the existing ag-grid's IHeaderComponent and modify the header content/behavior?
I created my own IHeaderComponent and used it in the ag-grid, but facing difficulty adding my own directive in the header. All the TS example on their site doesn't help much either, since I'm stuck with angular 1.6. In addition, what is the correct way to pass my dependencies to my IHeaderComponent since I cannot use IHeaderAngularComponent.
Any suggestions?
Edit:
My first stab of it, kind a ugly how I pass my dependencies, not sure if that is the proper way to do it.
class MyHeader {
/**
* #implements {IHeaderComp}
*/
constructor() {
if (!MyHeader.injector) {
MyHeader.injector = angular.element('[ng-app=myApp]').injector();
}
this.injector = MyHeader.injector;
this.dependencies = ['$log'];
}
/**
* #param {IHeaderCompParams} params
*/
init(params) {
this.params = params;
this.eGui = document.createElement('div');
this.eGui.innerHTML = '<span class="ag-header-cell-text" ref="eText" role="columnheader"></span>';
this.eText = this.eGui.querySelector(".ag-header-cell-text");
this.eText.textContent = params.displayName;
this.initAngular();
}
initAngular() {
this.dependencies = _.compact(this.dependencies);
this.dependencies.forEach(dep => this[dep] = this.injector.get(dep));
}
getGui() {
return this.eGui;
}
destroy() {
if (this.params.enableSorting) {
this.eGui.removeEventListener('click', this.sortRequestListener);
this.params.column.removeEventListener('sortChanged', this.onSortChangedListener);
}
}
onSortRequested(event) {
if (this.params.enableSorting) {
//...
}
}
onSortChanged() {
if (this.params.enableSorting) {
//...
}
}
initSorting() {
if (this.params.enableSorting) {
//...
}
}
}

Have you checked an official demo for custom headerComponent?
According to your code, to handle click, hover or any other event you need to define a listener. You are handling dispose with removeEventListener, which is good, but where is a subscription?
So as example, you need to append on init step:
let youHeader = this.eGui.querySelector(".ag-header-cell-text");
youHeader.addEventListener('click', this.youCustomClickHandler);
youCustomClickHandler(){
... your logic here
}
You can specify your enable\disable condition on init step (not exactly inside the function)

Related

Subclassing foreign Service does not work

I'm trying to subclassing the FileCollectionService class from third party extension. But it takes not place.
ext_typoscript_setup.txt:
config.tx_extbase{
persistence{
classes{
SKYFILLERS\SfFilecollectionGallery\Service\FileCollectionService {
subclasses {
TxFileCollectionService = FalkRoeder\MyExt\Service\FileCollectionService
}
}
}
}
}
my FileCollectionService.php put in Classes/Service
<?php
namespace FalkRoeder\MyExt\Service;
/**
* FileCollectionService
*/
class FileCollectionService extends \SKYFILLERS\SfFilecollectionGallery\Service\FileCollectionService {
/**
* #return array
*/
public function methodToOverwrite() {
...
}
}
to get it work, I needed to add the following code to ext_typoscript_setup.txt:
config.tx_extbase {
objects {
SKYFILLERS\SfFilecollectionGallery\Service\FileCollectionService.className = FalkRoeder\MyExt\Service\FileCollectionService
}
}
Try to something Like this.
config.tx_extbase{
persistence{
classes{
SKYFILLERS\\SfFilecollectionGallery\\Service\\FileCollectionService {
subclasses {
TxFileCollectionService = VendorName\ExtensionKey\Classes\Utility\FileCollectionService
}
}
}
}
}

how to config container with request variable

In the first place I had to configure parameters using the class "ParametersCompilerPass" to get data from database.Here si my class :
class ParametersCompilerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
$em = $container->get('doctrine.orm.default_entity_manager');
$boutique = $em->getRepository('AcmeBundle:Boutique')->findOneByNom($container->getParameter('boutique.config'));
if(null !== $boutique){
$container->setParameter('url_site', $boutique->getUrl());
$container->setParameter('idboutique', $boutique->getId());
}else{
$container->setParameter('url_site', null);
$container->setParameter('idboutique', 0);
}
}
}
and when i set a parameter from request, it dont work, i tried in adding this code :
$request = $container->get('request_stack')->getCurrentRequest();
if($request->getMethod() == 'POST'){
if (null !== $choixbout = $request->get('choixbout')){
// $this->container->setParameter('idboutique',$choixbout);
}
}
the service request_stack return null.
I do not know how to configure a parameter from a POST variable.
Hope you can help me.
thanks
Is it solid requirement to have the parameter set?
It could be handy to create a service which has a request dependency that can act as a boutique parameter holder.
For example
# app/config/services.yml
app.boutique:
class: AppBundle\Boutique\Boutique
arguments: ['#request_stack']
app.boutique_info_dependant1:
class: AppBundle\Boutique\BoutiqueDependant1
arguments: ['#app.boutique']
app.boutique_info_dependant2:
class: AppBundle\Boutique\BoutiqueDependant2
arguments: ['#app.boutique']
This would be a parameter handler.
# AppBundle/Boutique/Boutique.php
class Boutique
{
/** #var RequestStack */
private $requestStack;
/**
* BoutiqueListener constructor.
* #param ContainerInterface $container
*/
public function __construct(RequestStack $requestStack)
{
$this->requestStack = $requestStack;
}
public function getBoutique()
{
$request = $this->requestStack->getCurrentRequest();
/// here you can add an extra check if the request is master etc.
if ($request->getMethod() == Request::METHOD_POST) {
if (null !== $choixbout = $request->get('choixbout')) {
return $choixbout;
}
}
return null;
}
}
Then using the handler
class BoutiqueDependant1
{
public function __construct(Boutique $boutique)
{
$this->myBoutique = $boutique->getBoutique();
}
}
This does not look like the best solution but could work...
Other option would be to rethink the application architecture to handle boutique information somehow differently.

Dynamics AX 2012 Only One Copy of a Form Open

Anyone have any tips/code snippets for preventing more than one copy of a custom X++ form from being opened at a time?
Best case: Attempt to open another copy of the form, and the original gains focus
Acceptable: User receives a notice that the form is already open
you could insert the code below into the form's init method.
If you have any questions to the code don't hesitate to ask!
public void init()
{
#define.CACHE_OWNER ('MyForm')
#define.CACHE_KEY_INSTANCE ('Instance')
FormRun existingForm()
{
;
if (infolog.globalCache().isSet(#CACHE_OWNER, #CACHE_KEY_INSTANCE))
{
return infolog.globalCache().get(
#CACHE_OWNER, #CACHE_KEY_INSTANCE);
}
return null;
}
void registerThisForm()
{
;
infolog.globalCache().set(#CACHE_OWNER, #CACHE_KEY_INSTANCE, this);
}
boolean isAlreadyOpened()
{
;
return existingForm() ? !existingForm().closed() : false;
}
void activateExistingForm()
{
;
existingForm().activate(true);
}
;
super();
if (isAlreadyOpened())
{
activateExistingForm();
this.close();
}
else
{
registerThisForm();
}
}
Add the following code to the init method of the form as follows. No other changes are required.
public void init()
{
#define.CACHE_OWNER('MyForm')
int hWnd;
super();
if (infolog.globalCache().isSet(#CACHE_OWNER, curUserId()))
{
hWnd = infolog.globalCache().get(#CACHE_OWNER, curUserId());
}
if (WinApi::isWindow(hWnd))
{
element.closeCancel();
WinAPI::bringWindowToTop(hWnd);
}
else
{
infolog.globalCache().set(#CACHE_OWNER, curUserId(), element.hWnd());
}
}

Zend Framework 1.12 plugin for checking "Authorization" header

I'm writing REST api using Zend Framework 1.12. I want to check "Authorization" header in controller plugin.
I put code in the preDispatch action of the plugin
$authorizationHeader = $request->getHeader('Authorization');
if(empty($authorizationHeader)) {
$this->getResponse()->setHttpResponseCode(400);
$this->getResponse()->setBody('Hello');
die(); //It doesn't work
}
The problem is that after it controller's action is still being called. I tried 'die()', 'exit'. My question is how to return response from plugin and do not call controller's action.
Did a similar REST API with Zend several weeks ago with this approach:
Class Vars/Consts:
protected $_hasError = false;
const HEADER_APIKEY = 'Authorization';
My preDispatch:
public function preDispatch()
{
$this->_apiKey = ($this->getRequest()->getHeader(self::HEADER_APIKEY) ? $this->getRequest()->getHeader(self::HEADER_APIKEY) : null);
if (empty($this->_apiKey)) {
return $this->setError(sprintf('Authentication required!'), 401);
}
[...]
}
My custom setError Function:
private function setError($msg, $code) {
$this->getResponse()->setHttpResponseCode($code);
$this->view->error = array('code' => $code, 'message' => $msg);
$this->_hasError = true;
return false;
}
Then simply check if a error has been set inside your functions:
public function yourAction()
{
if(!$this->_hasError) {
//do stuff
}
}
If you're using contextSwitch and JSON, then your array with errors will be automatically returned & displayed, if an error occours:
public function init()
{
$contextSwitch = $this->_helper->getHelper('contextSwitch');
$this->_helper->contextSwitch()->initContext('json');
[...]
}
Hope this helps
Since checking headers is typically a low level request operation, you could do the header verification and then throw an exception if not valid in dispatchLoopStartup of the plugin. Then in your error controller, return the appropriate response. This would prevent the action from being dispatched/run and could be applied to any controller/action without modifying any controller code.
Controller plugin:
class AuthHeader extends Zend_Controller_Plugin_Abstract
{
public function dispatchLoopStartup(\Zend_Controller_Request_Abstract $request)
{
// Validate the header.
$authorizationHeader = $request->getHeader('Authorization');
if ($invalid) {
throw new Zend_Exception($error_message, $error_code);
}
}
}
Error handler:
class ErrorController extends Zend_Controller_Action
{
public function init()
{
// Enable JSON output for API originating errors.
if ($this->isApiRequest($this->getRequest())) {
$contextSwitch = $this->_helper->getHelper('contextSwitch');
$contextSwitch->addActionContext('error', 'json')
->setAutoJsonSerialization(true)
->initContext('json');
}
}
public function errorAction()
{
// Handle authorization header errors
// ...
// Handle errors
// ...
}
public function isApiRequest($request)
{
// Determine if request is an API request.
// ...
}
}

Facebook.addJSEventListener callback function not being called

I am creating a facebook application with the help of Facebook graph API in Actionscript3. For some weird reason 2 days ago Facebook.addJSEventListener decided not to call the callback function anymore.
Here is my code:
static public function ConnectToApp(sAppID_:String , sPermissions_:String, sRedirectURL_:String):void
{
sAppID = sAppID_;
sPermissions = sPermissions_;
sRedirectURL = sRedirectURL_;
Facebook.init(sAppID, loginHandler);
}
static private function loginHandler(objectSession_:Object,objectFail_:Object):void
{
if( objectSession_ == null)
{
ExternalInterface.call("redirect",sAppID, sPermissions,sRedirectURL);
}
Facebook.addJSEventListener('auth.statusChange', detectLogin);
}
static private function detectLogin(userInfo_:Object):void
{
if (userInfo_.status == "connected")
{
iUserStatus = Globals.FB_USER_CONNECTED;
iUserID = userInfo_.authResponse.userID;
Facebook.api('/me' ,getMeHandler);
Security.loadPolicyFile("http://profile.ak.fbcdn.net/crossdomain.xml");
sProfilePicURL = Facebook.getImageUrl(iUserID.toString());
loadMyPicture();
}
else if (userInfo_.status == "not_authorized")
{
iUserStatus = Globals.FB_USER_NOT_AUTHORIZED;
}
else
{
iUserStatus = Globals.FB_USER_NOT_CONNECTED;
}
}
Facebook.init is calling the loginHandler callback function but Facebook.addJSEventListener('auth.statusChange', detectLogin); decides not to.
Thank you in advance for all the help.
I was able to get it to work. I did the following code change:
static public function ConnectToApp(sAppID_:String , sPermissions_:String, sRedirectURL_:String):void
{
sAppID = sAppID_;
sPermissions = sPermissions_;
sRedirectURL = sRedirectURL_;
Facebook.init(sAppID, loginHandler);
}
static private function loginHandler(objectSession_:Object,objectFail_:Object):void
{
if( objectSession_ == null)
{
ExternalInterface.call("redirect",sAppID, sPermissions,sRedirectURL);
return;
}
GetAllInfo();
}
static private function GetAllInfo():void
{
iUserStatus = Globals.FB_USER_CONNECTED;
iUserID = int(Facebook.getAuthResponse().uid);
Facebook.api('/me' ,getMeHandler);
Security.loadPolicyFile("http://profile.ak.fbcdn.net/crossdomain.xml");
sProfilePicURL = Facebook.getImageUrl(iUserID.toString());
loadMyPicture();
}
So basically now I'm not adding an event listener that calls a callback function when the user is connected, if the session is not ready I redirect and return... when the session is ready I automatically start getting the information.
I am not sure if I will ever get a problem where I start asking for the info before fully logging in but so far I did a lot of tests and it seems to work.
If anyone has a better solution please let me know.