Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#5525 - Simplify Program Deletion Process #5583

Conversation

ujjwalpathaak
Copy link
Contributor

@ujjwalpathaak ujjwalpathaak commented Jan 13, 2024

refs - #5525

image
/home/ujjwalpathaak/WikiEduDashboard/app/views/campaigns/_course_row.html.haml - this page has actions mentioned for clone and remove

 - if @presenter&.can_remove_course?
      %a.course-link{:href => "#{course_slug_path(course.slug)}"}
        = form_for(@campaign, url: remove_course_campaign_path(@campaign.slug, course_id: course.id), method: :put, id: "remove_course-#{course.id}", html: { class: 'remove-program-form' }) do
          = hidden_field_tag('course_title', course.title, id: "course_title-#{course.id}")
          %button.button.danger.remove-course{'data-id' => course.id, 'data-title' => course.title, 'data-campaign-title' => @campaign.title}
            = t('assignments.remove')

This is the code for remove button - if i can get a prop to check if user is allowed to delete the course + if no of campaigns = 1
just like it's done here - /home/ujjwalpathaak/WikiEduDashboard/app/assets/javascripts/components/overview/available_actions.jsx

 delete() {
    // The action is only available once a course has been removed from all campaigns.
    if (this.props.course.published) {
      return alert(I18n.t('courses.delete_course_instructions'));
    }

    const enteredTitle = prompt(I18n.t('courses.confirm_course_deletion', { title: this.props.course.title }));
    if (enteredTitle.trim() === this.props.course.title.trim()) {
      return this.props.deleteCourse(this.props.course.slug);
    } else if (enteredTitle) {
      return alert(I18n.t('courses.confirm_course_deletion_failed', { title: enteredTitle }));
    }
  },

  if ((user.isAdvancedRole || user.admin) && (!course.published || !Features.wikiEd)) {
        controls.push((
          <div title={I18n.t('courses.delete_course_instructions')} key="delete" className="available-action">
            <button className="button danger" onClick={this.delete}>
              {CourseUtils.i18n('delete_course', course.string_prefix)}
            </button>
          </div>
        ));
      }

I can replicate the functinianlity and add the button in the haml file -- so the user can delete the programs directly from campaign's list of programs.

@ujjwalpathaak ujjwalpathaak marked this pull request as draft January 13, 2024 15:40
@ujjwalpathaak
Copy link
Contributor Author

@ragesoss let me know the changes.

This is how the delete process is working rn
Screencast from 13-01-24 08:57:37 PM IST.webm

  • I think if only 1 campaign is there then delete button should be visible otherwise remove button only.
  • This snippet needs to be updated with correct permissions. maybe? - presenters/courses_presenter.rb
     def can_delete_course?
        @can_remove ||= current_user&.admin? || campaign_organizer?
     end
  • I need to change the behaviour -- after the title is correctly entered and course is deleted it's going to the response .json file.

@ujjwalpathaak
Copy link
Contributor Author

@ragesoss LMKYT regarding the commit

@ujjwalpathaak ujjwalpathaak changed the title [WIP] #5525 - Simplify Program Deletion Process #5525 - Simplify Program Deletion Process Jan 27, 2024
@ujjwalpathaak ujjwalpathaak marked this pull request as ready for review January 27, 2024 13:22
@ujjwalpathaak
Copy link
Contributor Author

@ragesoss I think this PR is ready for review.

@ujjwalpathaak
Copy link
Contributor Author

@ragesoss I have made a few changes, but i need help in one of the changes required in app/presenters/courses_presenter.rb. LMKWYT.

@ujjwalpathaak
Copy link
Contributor Author

Hi @ragesoss, I have made the necessary changes.

  • Made a child controller
  • Simplified the workflow + a tiny change in the workflow
  • Added a comment

1) Course with only 1 campaign

Program 24 is only in one campaign, so after clicking "Remove and Delete" it removes the program also delete it, to notify that action it provokes a notification. --

course_removed_and_deleted: '"%{title}" has been deleted and removed from the "%{campaign_title}" campaign'

Screencast.from.18-02-24.03.20.00.PM.IST.webm

2) Course with 1+ campaigns

Program 23 is in more than one campaign, so after clicking "Remove and Delete" it removes the program but dosent delete it, to notify that action it provokes a notification. --

course_removed_but_not_deleted: '"%{title}" has been removed from the "%{campaign_title}" but has not been deleted as it is present in other campaigns as well'

Screencast.from.18-02-24.03.19.37.PM.IST.webm

@ujjwalpathaak
Copy link
Contributor Author

@ragesoss i have made the changes

@ragesoss ragesoss merged commit ecc77bb into WikiEducationFoundation:master Mar 1, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants