How to call Prompt message in VF SLDS page from Controller

I have a VF page that has the SLDS styling. The page is being triggered from a button on a Case object. I would like to display a message as soon as the page is loaded, if the Case Contact email is blank.

Here is part of my Controller:

public class LTRORequireAdditionalDocumentsCon {

    public LTRO_Document__c ltrodoc {get;set;}
    public String caseId;
    public String contId;
    public String contEmail {get; set;}
    public String contName {get; set;} 
    public String emailBody {get; set;}
    public String emailBodyTxt {get; set;}
    public String SandboxName;
    public String sfdcBaseURL;
    public Case LTROdauLink;
    public Boolean hasConEmail{set;}


    public List ltrodoclist {get; set;}

    public LTRORequireAdditionalDocumentsCon(){


        ltrodoc = new LTRO_Document__c();
        ltrodoclist = new List();

        if(contEmail == null){
           hasConEmail = false;

        }

    }

I am not sure how to set up my Vf page so it is utilizing SLDS to display Prompt message. I found this info on SLDS site https://lightningdesignsystem.com/components/prompt/, but not sure how to call the prompt in my page so this message pops up.

Any help is greatly appreciated.

Thanks

How to properly sanitize the input from an admin form on save and when referenced in controller class?

We have an admin form that has two text fields (‘pattern’ and ‘host’). In a ControllerClass we have to use the input to perform some logic.

How would we properly sanitize the input from the two text fields on save of text field values and when retrieving the value in a controller class?

Current code:

class MyModule extends ProviderPluginBase {
  public function _some_function($input) {
    $mymodule_config = Drupal::config('mymodule.settings');
    $host = $mymodule_config->get('host');
    $pattern = $mymodule_config->get('pattern');

    /* we will need to use the $host and $pattern */
}

We initially thought that HTML::escape would work, but that is for output. Not sure how to sanitize the input.

Example of what we tried for the controller class:

$escapted_value = _some_sanitization_function($pattern);

When saving the text field value:

public function submitForm(array &$form, FormStateInterface $form_state) {
  $config = $this->config('mymodule.settings');
  $config
    ->set('pattern', _some_sanitization_function($form_state->getValue('pattern'))
    ->set('host', _some_sanitization_function($form_state->getValue('host'))
    ->save();
}

How to write test class for below custom controller class? [on hold]

public class EmployeeRegistrationController 
{
    public String selectedTab{get; set;}
    public EmpID__c EmpID{get;set;}
    public EmployeeInfo__c EmpDetail{get; set;}
    public EducationInfo__c EduDetail{get; set;}
    public List listEducation {get; set;}
    public TechnologyInfo__c TechDetail{get;set;}
    public List listTechnology {get;set;}
    public List listEduInsert {get; set;}
    public List listTechInsert{get;set;}
    public Boolean button{get;set;}
    public Boolean btnSubmit{get;set;}
    public Boolean btnSave{get;set;}

    public EmployeeRegistrationController()
    {
        selectedTab='Employee';
        EmpDetail=new EmployeeInfo__c();
        listEducation=new List();
        TechDetail=new TechnologyInfo__c();
        listTechnology=new List ();
        EmpID=new EmpID__c();
        button=true;
        btnSubmit=true;
        btnSave=false;
    }

    public void goNext1()
    {
        selectedTab='Education';
    }

    public PageReference saveInfo()
    {
        if(EmpDetail.First_Name__c==null||EmpDetail.Last_Name__c==null||EmpDetail.Email__c==null)
        {
            ApexPages.Message msg=new ApexPages.Message(ApexPages.Severity.ERROR,'Please fill Basic details: First Name, Last Name, Email ID');
            ApexPages.addMessage(msg);
        }
        else
        {
        try
        {
            insert EmpDetail;
            ID Eid=[select ID from EmployeeInfo__c where Email__c=:EmpDetail.Email__c limit 1].ID;
            EmpID=new EmpID__c(Eid__c=Eid);
            button=false;
            btnSave=true;
        }
        catch(Exception e)
        {
            System.debug(e.getMessage());
        }
       }
        return null;
    }

    public void goNext2()
    {
        selectedTab='Technology';
    }

    public PageReference addNewRow()
    {
        if(EmpID.Eid__c==null)
        {
            ApexPages.Message msg=new ApexPages.Message(ApexPages.Severity.ERROR,'Please fill the Basic detail First');
            ApexPages.addMessage(msg);
        }
        else
        {
        EduDetail=new EducationInfo__c();
        EduDetail.Employee__c=EmpID.Eid__c;
        listEducation.add(EduDetail);
        }
        return null;
    }

    public PageReference saveEducation()
    {
        for (EducationInfo__c c:listEducation)
        {
        if(c.course__c==null)
        {
            ApexPages.Message msg=new ApexPages.Message(ApexPages.Severity.ERROR,'Please fill the details');
            ApexPages.addMessage(msg);
        }
        else
        {
            try
            {
                upsert listEducation;
                listEduInsert=[SELECT Name, course__c,From_Date__c,To_Date__c FROM EducationInfo__c WHERE Employee__c=:EmpID.Eid__c];
            }
            catch(Exception e)
            {
                System.debug(e.getMessage());
            }
        }
        }
        listEducation.clear();
        return null;
    }

    public PageReference addNewRow2()
    {
        TechDetail=new TechnologyInfo__c();
        TechDetail.Employee__c=EmpID.Eid__c;
        listTechnology.add(TechDetail);
        return null;
    }

    public PageReference saveTechnology()
    {
        for(TechnologyInfo__c t: listTechnology)
        {
        if(t.Skill__c==null)
        {
            System.debug(t.Skill__c);
            ApexPages.Message msg=new ApexPages.Message(ApexPages.Severity.ERROR,'Please fill the details');
            ApexPages.addMessage(msg);
            System.debug(msg);
        }
        else
        {
            try
            {
                upsert listTechnology;
                listTechInsert =[SELECT Name, Experience__c,Level__c,Skill__c FROM TechnologyInfo__c WHERE Employee__c=:EmpID.Eid__c];
                btnSubmit=false;
            }
            catch(Exception e)
            {
                System.debug(e.getMessage());
            }
        }
        }
        listTechnology.clear();
        return null;
    }

    public PageReference submit()
    {
        SentEmail.sentToAdmin(EmpID.Eid__c);
        SentEmail.sentToUser(EmpID.Eid__c);
        PageReference pageRefer=new PageReference('/apex/FinalPage');
        pageRefer.setRedirect(true);
        return pageRefer;
    }
}

*******************Test class fro above class***********************
@isTest
private class TestEmployeeRegistration {

@isTest static void testData()
{

    EmployeeInfo__c EmpDetail=new EmployeeInfo__c();
    //List listEmp=new List();
    EmpDetail.First_Name__c='Test';
    EmpDetail.Last_Name__c='Test';
    EmpDetail.Email__c='test@test.com';
    EmpDetail.Contact_No__c=123456789;
    EmpDetail.City__c='Test';
    EmpDetail.Address__c='Test';
    //listEmp.add(EmpDetail)
    insert EmpDetail;

    EducationInfo__c EduDetail=new EducationInfo__c();
    List listEdu=new List();
    EduDetail.Employee__c=EmpDetail.Id;
    EduDetail.course__c='Test';
    EduDetail.From_Date__c=Date.newInstance(2018, 10, 10);
    EduDetail.To_Date__c=Date.newInstance(2018, 11, 11);

    TechnologyInfo__c TechDetail=new TechnologyInfo__c();
    List listTech=new List();
    TechDetail.Employee__c=EmpDetail.Id;
    TechDetail.Skill__c='Test';
    TechDetail.Experience__c=2;
    TechDetail.Level__c='Expert';

    Test.startTest();
    EmployeeRegistrationController controllerClass=new EmployeeRegistrationController();
    controllerClass.goNext1();
    System.assertEquals('Education', controllerClass.selectedTab);

    controllerClass.saveInfo();
    controllerClass.goNext2();
    System.assertEquals('Technology', controllerClass.selectedTab);

    controllerClass.addNewRow();

    controllerClass.EduDetail=new EducationInfo__c();
    controllerClass.saveEducation();
    listEdu.add(EduDetail);
    upsert listEdu;
    controllerClass.listEduInsert=[SELECT Name, course__c,From_Date__c,To_Date__c FROM EducationInfo__c WHERE Employee__c=:EmpDetail.Id];
    controllerClass.addNewRow2();

    listTech.add(TechDetail);
    upsert listTech;
    controllerClass.saveTechnology();
    controllerClass.btnSubmit=false;
    controllerClass.listTechInsert=[SELECT Name, Experience__c,Level__c,Skill__c FROM TechnologyInfo__c WHERE Employee__c=:EmpDetail.Id];
    System.assertEquals(false,controllerClass.btnSubmit);

    controllerClass.submit();
    Test.stopTest();
}

@isTest static void testDataMethod()
{
    EmployeeInfo__c EmpDetail=new EmployeeInfo__c();
    EmpDetail.First_Name__c='Test';
    EmpDetail.Last_Name__c='Test';
    EmpDetail.Email__c='test@test.com';
    EmpDetail.Contact_No__c=123456789;
    EmpDetail.City__c='Test';
    EmpDetail.Address__c='Test';
    insert EmpDetail;

    Test.startTest();
    EmployeeRegistrationController controllerClass=new EmployeeRegistrationController();
    EmployeeInfo__c EmpDetail2=new EmployeeInfo__c(First_Name__c='',Last_Name__c='',Email__c='');
    controllerClass.saveInfo();
    insert EmpDetail2;
    ID Eid=[select ID from EmployeeInfo__c where Email__c=:EmpDetail.Email__c limit 1].ID;
    EmpID__c EmpID=new EmpID__c(Eid__c=EmpDetail.Id);
    controllerClass.button=false;
    controllerClass.btnSave=true;
    Test.stopTest();

    System.assertEquals(false,controllerClass.button);
}


@isTest static void testDataMethod2()
{
    EmployeeInfo__c EmpDetail=new EmployeeInfo__c();
    //List listEmp=new List();
    EmpDetail.First_Name__c='Test';
    EmpDetail.Last_Name__c='Test';
    EmpDetail.Email__c='test@test.com';
    EmpDetail.Contact_No__c=123456789;
    EmpDetail.City__c='Test';
    EmpDetail.Address__c='Test';
    //listEmp.add(EmpDetail)
    insert EmpDetail;

    EducationInfo__c EduDetail=new EducationInfo__c();
    List listEdu=new List();
    EduDetail.Employee__c=EmpDetail.Id;
    EduDetail.course__c=null;
    EduDetail.From_Date__c=Date.newInstance(2018, 10, 10);
    EduDetail.To_Date__c=Date.newInstance(2018, 11, 11);
    Test.startTest();
    EmployeeRegistrationController controllerClass=new EmployeeRegistrationController();

    controllerClass.saveEducation();
    upsert EduDetail;
    Test.stopTest();
}

@isTest static void testDataMethod3()
{
    EmployeeInfo__c EmpDetail=new EmployeeInfo__c();
    EmpDetail.First_Name__c='Test';
    EmpDetail.Last_Name__c='Test';
    EmpDetail.Email__c='test@test.com';
    EmpDetail.Contact_No__c=123456789;
    EmpDetail.City__c='Test';
    EmpDetail.Address__c='Test';

    Test.startTest();
    EmployeeRegistrationController controllerClass=new EmployeeRegistrationController();
    controllerClass.addNewRow();
    EducationInfo__c newEdu=new EducationInfo__c();
    controllerClass.listEducation.add(newEdu);
    insert EmpDetail;
    controllerClass.EmpDetail.Id=EmpDetail.Id;
    Test.stopTest();
}

}

Laravel controller for a commenting system

Can someone review my Controller? I should follow these guidelines:

Code should be written with MVC pattern and to use OOP.

The code now works fine, but I need to improve it. Also, should I use more Ajax Model?

This code is used to receive data from a jQuery script and send it back. Almost every method does the same.

insert(array(
                            'name'   => $name,
                            'comment' => $comment,
                            'current_date' => $date,
                            'avatar'  => $img
                        ));

            $id = DB::getPdo()->lastInsertId();

                if($qv){
                $out = array('date' => $date,
                            'userID' => $userID,
                             'comment' => $comment,
                            'comment_id' => $id,
                            'userName' => $name,
                            'photo_img' => $img);

                return Response::make(json_encode($out));
            }
            }

        }
        public function reply()
    {
              if(Input::get('task') && Input::get('task') == 'reply_insert'){
                $commentID = Input::get('commentID');
                $comment = nl2br(Input::get('comment'));
                $name = Input::get('name');
                $date = Input::get('date');
                $level = Input::get('levelBR');
                $order= Input::get('order');
                $id_rep = Input::get('id_rep');
                $nametorep = Input::get('nametorep');
                $level += 1;
                    if(Input::get('picture')){
                         $img = Input::get('picture');
                    }else{
                         $img = 'http://thecontentwrangler.com/wp-content/uploads/2011/08/User.png';
                    }
                    if($order == 'NULL'){
                        $order = NULL;
                    }
                    $qv = DB::table('replays')
                          ->insert(array(
                              'name'   => $name,
                              'comment' => $comment,
                              'comment_integer' => $commentID,
                              'level'   => $level,
                              'nametorep' => $nametorep,
                              'current_date' => $date,
                              'order' => $order,
                              'avatar' => $img
                          ));

                    $id = DB::getPdo()->lastInsertId();

                    $out = array(
                                'date' => $date,
                                'order' => $order,
                                'nametorep' => $nametorep,
                                'commentID' => $commentID,
                                'comment' => $comment,
                                'replyID' => $id,
                                'name'    => $name,
                                'levelBR' => $level,
                                'photo_img' => $img
                    );

                    return Response::make(json_encode($out));

            }

        }


        public function checkHash($table,$colCol,$colRep,$comment,$reply){
                if($reply == 'NULL'){
                  $hashs = DB::select("SELECT * FROM $table WHERE $colRep IS NULL && $colCol =?", array($comment));

                }else{
                   $hashs = DB::select("SELECT * FROM $table WHERE $colRep = ? && $colCol =?", array($reply,$comment ));
                }

                foreach ($hashs as $h){
                    if(Cookie::get($h->hash)){
                        return true;
                    }
                 }

      }

        public static function make($string,$salt=''){
                return hash('sha256',$string . $salt);
        }

        public static function unique(){
                return self::make(uniqid());
        }

        public function upVote(){
          if(Input::get('task') && Input::get('task') == true){
              $reply = Input::get('reply');
              $comment = Input::get('comment');
              $vote  = Input::get('vote');
              $voteCom  = Input::get('voteCom');
              intval($vote);
              intval($voteCom);
                if (self::checkHash('hashs','comment_integer','reply_integer',$comment,$reply)) {
                    $out1= array('voted' => 'You have already voted.');
                     return json_encode($out1);
                 }  else {
                    $hash = self::unique();
                    $cookie = Cookie::forever($hash, 7);

                        if($reply == 'NULL'){
                            $reply = NULL;
                            DB::table('comments')->where(array('id' => $comment ))->increment('vote_up', 1);

                        }else{
                            DB::table('replays')->where(array('id' => $reply,'comment_integer' => $comment ))->increment('vote_up', 1);
                        }

                  DB::table('hashs')->insert(array('comment_integer' => $comment, 'reply_integer' => $reply,'hash' => $hash)); 
                  $vote = $vote + 1;
                  $voteCom = $voteCom +1;
                  $out = array('vote' => $vote,'voteCom' => $voteCom);

                 return Response::make(json_encode($out))-> withCookie($cookie);

            }

          }

          }




          public function downVote(){
          if(Input::get('task')){

              $reply = Input::get('reply');
              $comment = Input::get('comment');
              $vote  = Input::get('vote');
              $voteCom  = Input::get('voteCom');
              intval($vote);
              intval($voteCom);
                    if (self::checkHash('hashs','comment_integer','reply_integer',$comment,$reply)) {
                        $out1= array('voted' => 'You have already voted.');
                        return json_encode($out1);
                     }  else {

               $hash = self::unique();
               $cookie = Cookie::forever($hash, 7);

                    if($reply == 'NULL'){
                        $reply = NULL;
                        DB::table('comments')->where(array('id' => $comment ))->increment('vote_down', 1);

                    }else{
                        DB::table('replays')->where(array('id' => $reply,'comment_integer' => $comment ))->increment('vote_down', 1);
                    }
                  DB::table('hashs')->insert(array('comment_integer' => $comment, 'reply_integer' => $reply,'hash' => $hash)); 
                  $vote = $vote + 1;
                  $voteCom = $voteCom +1;
                  $out = array('vote' => $vote,'voteCom' => $voteCom);

                     return Response::make(json_encode($out))-> withCookie($cookie);

            }

          }

          }


          public function report(){
              if(Input::get('task')){
                 $commentID = Input::get('comment');
                 $replyID =Input::get('reply');

                        if(self::checkHash('hashreport','comment_report_id','reply_report_id',$commentID,$replyID)){
                            $out1= array('reported' => 'Comment already reported.');
                            return json_encode($out1);
                        }  else {
                      $hash = self::unique();
                      $cookie = Cookie::forever($hash, 7);

                      if($replyID == 'NULL'){
                          $replyID = NULL;
                          DB::table('comments')->where(array('id' => $commentID ))->increment('report', 1);

                      }else{
                          DB::table('replays')->where(array('id' => $replyID,'comment_integer' => $commentID ))->increment('report', 1);
                      }

                         DB::table('hashreport')->insert(array('comment_report_id' => $commentID, 'reply_report_id' => $replyID,'hash' => $hash)); 

                         $out = array('report' => 'This comment is reported. Thanks!');

                        return Response::make(json_encode($out))-> withCookie($cookie);
                  }


              }
          }

          private function getComments($order){
             $comments = DB::select("SELECT avatar,name, vote_up,vote_down,report,id,comment,`current_date`,comment_integer,level FROM ( SELECT avatar,name, vote_up,vote_down,report,id,comment,`current_date`,comment_integer,level  FROM comments UNION ALL SELECT avatar,name, vote_up,vote_down,report,id,comment,`current_date`,comment_integer,level  FROM replays ) T ORDER BY $order DESC");

             return $comments;
          }

          public function bylikes(){
              //SELECT name, vote_up FROM ( SELECT name, vote_up FROM comments UNION ALL SELECT name, vote_up FROM replays ) T ORDER BY vote_up DESC
                if(Input::get('task')){
                 return json_encode(self::getComments('vote_up'));
                }

          }

          public function bydiss(){
              //SELECT name, vote_up FROM ( SELECT avatar,name, vote_up FROM comments UNION ALL SELECT name, vote_up FROM replays ) T ORDER BY vote_up DESC
           if(Input::get('task')){
               return json_encode(self::getComments('vote_down'));
           }

          }
}

Practically implementing a torque controller

I’m currently working on a robotics project where i have to build a quadruped. i have somewhat finished the designing for the time being and now moving into simulations. I have followed a inverse dynamics approach to build the controller of the leg following this blog and i have added,

                       Torque = Jacobean' * force

equation to the control equation in order to exert required reaction force and other forces. Meanwhile i have to order required parts to build a model early on due to delivery time. i selected PMDC to control the robot but have been restricted to cheap ones since the budget is low.

The problem is selecting a controller circuit. Since the control signal from the dynamics model outputs a torque value and since DC motor torque is proportional to current, i understand that i have to control the current of the motor. But all the motor controllers i found in USD 1-100 range only controls speed(Voltage) of the motor. The cheapest one i found is dual motor controller for USD 100. But it is out of my reach because i have to control 12 dc motors. what are the options i have?

1) can i achieve this by modifying a general motor controller? or is there a controller i can use in USD 1-50 range?

2) i looked in sparkfun, pololu sites for no success. but robotpower.com had a board called megamoto which i came across but doesn’t say that i can current control using this. anyone who has experience with this?

3) Can anyone give me a schematic for a simple motor controller that can control the current. (i understand that i can achieve this by using mosfets, gate driver ics, shunt resistors and current sense amplifiers but doesn’t have much knowledge regarding the selection of components or designing of motor controllers.

4) are there any other methods to approach this?

Thank you

How to get Child Component value from Parent component in JS controller?

Child Component – SearchBarCmp.cmp


    

Child JS Controller – SearchBarCmpController.js

({
    searchKeyChange: function(component, event, helper) {
        var myEvent = $A.get("e.c:SearchKeyChange");
        myEvent.setParams({"searchKey": event.target.value});
        myEvent.fire();
    }
})

Event – SearchKeyChange.evt


    

Parent Component



            

Parent JS Controller

searchKeyChange : function(component, event, helper){
var SearchKey = event.getParam("searchKey");
//SearchKey provides the value of child component ie)SearchBarCmp.cmp input field value 
},
GetWrapperValues :function(component, event, helper){
   //How to get the value from child component in this JS controller??
}

How to get the value from child component in this JS controller GetWrapperValues ??

Suggestions Please

como puedo llenar varios gráfico y tablas con datos desde controller MVC5?

Hola estoy intentando hacer varias operaciones sobre mi vista .cshtml, los datos los estoy enviando desde el siguiente método, desde mi controlador y funciona para llenar una tabla y un gráfico, pero estoy intentando llenar varios gráfico don diferentes datos y no funciona.

   [HttpPost]
public JsonResult VentaServicio(string año,string mes)
{
    ReportDmsModel model = new ReportDmsModel();
   var años = Convert.ToInt32(año);
   var meses = Convert.ToInt32(mes);

    model.VentaServiciosTallerList = _servicioReportesDms.ReportVentaServicio(años, meses);
    model.VentaServiciosTallerList2 = _servicioReportesDms.ReportVentaServicio(años);
    return Json(model);// si envió todo el model, es decir dos listas.

   // si envió solo una lista  return Json(model.VentaServiciosTallerList);         }

mi vista actual que funciona si solo le envió una lista del model en este caso le estoy enviando todo el model

@model MBC.Models.ReportDms.ReportDmsModel
@{
    ViewBag.Title = "VentaServicio";
    Layout = "~/Views/Shared/_AdminLayout.cshtml";
}
@Html.HiddenFor(P => P.VentaServiciosTaller.año, new { id = "año" })
@Html.HiddenFor(P => P.VentaServiciosTaller.mes, new { id = "mes" })

@*intente también enviarle un ViewBag

@if (ViewBag.VentaServiciosTallerList != null)
{
    for (int i = 0; i < ViewBag.VentaServiciosTallerList; i++)
    {
        @Html.TextBoxFor(v=> v.VentaServiciosTallerList[i].asesor, new { id = "as" })
    }
}*@