Coder Social home page Coder Social logo

autooption's Introduction

AutoOption

.NET NuGet Version License: MIT
A simple library to generate options page for websites

autooption

Why

In every website, we need an options page (or setting page) where users can change some configs inside. Such as the number of rows in the lists, allowing comments on posts or not, changing themes and any other things.
To have any of those inputs in your options page, you should create a row in your table, create an input in the front-end, write the logic for that in the back-end and inserting its value in DB when every user clicks on the save button.

With AutoOption you can create any input inside your options page in a couple of seconds

Demo

autooption

Installation

Install AutoOption and AutoOption.Pages from NuGet to your project

Setup

(If you have Database and ConnectionString, skip the step 1 and 2)

  1. Create a Database

  2. Create a ConnectionString
    Create a ConnectionString the way you want or like my ConnectionString in appsettings.json (like here)

  3. Options Class
    Create an empty class with Options name wherever you want

  4. Options Page

    1. Right click on Pages folder, Add, Razor Page and choose Razor Page - Empty. then write Options for name or whatever you want

    2. In Options.cshtml.cs delete OnGet() function and add these two lines in OptionsModel class:

      [BindProperty]
      public IFormCollection Inputs { get; set; }
    3. delete all code inside the Options.cshtml and add this code instead:

       @page
       @addTagHelper *, AutoOption.Pages
       @model OptionsModel
      
       <vc:option inputs="@Model.Inputs"></vc:option>
  5. Config
    in Startup.cs set your ConnectionString to OptionHelper.Config

    OptionHelper.Config(typeof(Options),
          new SqlWrapper(Configuration.GetConnectionString("DefaultConnectionString")));

Usage

Now everything is ready. You can add any input to your options page just by writing properties in the options class.
Let's add a field of number and text type. You need to just add these two properties in your options class

public int PageCount { get; set; }
public bool AllowComment { get; set; }

Now build your project and go to https://localhost:44378/Options
Done.

If you want to have pretty titles, use Display attribute at top of the properties

[Display(Name = "Page Count")]
public int PageCount { get; set; }

[Display(Name = "Allow Comment")]
public bool AllowComment { get; set; }


If you want to access the value of fields programmatically, write like this

int count = OptionHelper.Get<Options>().PageCount;


If you want to change the value of fields programmatically, write like this

OptionHelper.Set(() => OptionHelper.Get<Options>().PageCount, 10);


Also, you can add enum property and you will see a Select input equivalently. (like here)

autooption's People

Contributors

sasan-salem avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

alinv20

autooption's Issues

Enum Support

User can use enum in option class and because that, in option page we must have dropdown.

Checkbox view for enums

View checkbox as an enum. There is needed to create a new attribute for enum to specify checkbox view.
Then we need a new type named EnumChBx and consider it in the whole project

Option property whitout display

Users have to use Display attribute in Option class. it's needed to eliminate this compulsion and when a property hasn't Display attribute, use property's name instead.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.