Create filters based on the UseraName, to get the filtered result in the page

Comments

N.kishorekumar created an issue. See original summary.

n.kishorekumar’s picture

StatusFileSize
new3.67 KB

code for the filter based on uid in the current user listing page,

Please find the patch

n.kishorekumar’s picture

Status: Active » Needs review
xaiwant’s picture

Assigned: n.kishorekumar » heykarthikwithu
Status: Needs review » Reviewed & tested by the community

@N.kishorekumar i can view use id filter has been added for currently logged in user.
seems ok .
moved to RTBC

krknth’s picture

Status: Reviewed & tested by the community » Needs work

Instead of uid, pls use username

krknth’s picture

Issue summary: View changes
n.kishorekumar’s picture

Status: Needs work » Needs review
StatusFileSize
new3.71 KB

@krknth
Replaced user id search with user name filter

heykarthikwithu’s picture

Assigned: heykarthikwithu » n.kishorekumar
Status: Needs review » Needs work

patch not applying.

root@ubuntu:/var/www/html/d8# git apply -v 2700431-7.patch
Checking patch src/Form/CLUListingUsers.php...
Hunk #1 succeeded at 29 (offset 2 lines).
Hunk #2 succeeded at 46 (offset 2 lines).
Hunk #3 succeeded at 101 (offset 2 lines).
error: while searching for:
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $current_user = \Drupal::currentUser();
    $uids = $form_state->getValues()['table'];
    foreach ($uids as $delete_session_uid) {
      $user = user_load($delete_session_uid);
      if ($current_user->id() != $delete_session_uid && $delete_session_uid != 0) {
        db_delete('sessions')
          ->condition('uid', $delete_session_uid)
          ->execute();
        drupal_set_message(t('@username ( @userid ) user session has been ended.', [
          '@username' => $user->getAccountName(),
          '@userid' => $user->id(),
        ]));
      }
    }
  }

error: patch failed: src/Form/CLUListingUsers.php:95
error: src/Form/CLUListingUsers.php: patch does not apply
n.kishorekumar’s picture

Status: Needs work » Needs review
StatusFileSize
new2.65 KB

Please find the updated patch

xaiwant’s picture

Assigned: n.kishorekumar » xaiwant
xaiwant’s picture

Assigned: xaiwant » heykarthikwithu
Status: Needs review » Reviewed & tested by the community

@N.kishorekumar, Username filter is working as per expected

Few minor changes needs to be updated.

1. Can we have button in right side of search field. Or else we should have space below.

+    $form['search_user'] = array(
+      '#type' => 'textfield',
+      '#title' => 'Username',
+    );
+    $form['search_submit'] = array(
+      '#type' => 'submit',
+      '#value' => 'Search',
+    );

2. Intendation problem exist here

+    $submit_value = $form_state->getValues()[op];
+    if ($submit_value == 'End sessions') {
+      if (empty($value_checked)) {
       $form_state->setErrorByName('clu_table', $this->t('Please select atleast one user to terminate the session.'));
     }
   }
+  }
+    if ($submit_value == 'End sessions') {
     $current_user = \Drupal::currentUser();
     $uids = $form_state->getValues()['table'];
     foreach ($uids as $delete_session_uid) {
@@ -112,6 +131,7 @@ class CLUListingUsers extends FormBase {
       }
     }
   }
+  }

3. reading op, needs to be read as a string.
+ $submit_value = $form_state->getValues()[op];

4. should be append with out changing existing query.

 +    if (isset($search_uname) && !empty($search_uname)) {
+      $query->condition('u.name', db_like($search_uname) . '%', 'LIKE');
+    }

5. line of code can be optimized in this case $search_uname

refer: https://www.drupal.org/coding-standards

xaiwant’s picture

xaiwant’s picture

Issue tags: +Coding standards
n.kishorekumar’s picture

StatusFileSize
new3.67 KB

Code was updated with the coding standards...
Please find the patch

heykarthikwithu’s picture

Assigned: n.kishorekumar » Unassigned
Status: Reviewed & tested by the community » Fixed
Parent issue: » #2698309: Search the users in the clu listing form

Committed with few changes..

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.