use ihboxsystem

delete from frontend.menu where  name = 'Ladle History'

delete from frontend.routes where ModuleName='ladle-history'


INSERT INTO [FrontEnd].[Routes]
           ([Route]
           ,[ModuleName]
           ,[ModulePath]
           ,[RequiredRole]
       )
     VALUES
           (
		   '!/ladle-history(/:ladleId)(/:start)(/:end)'
           , 'ladle-history'
		   , 'custom-screens/ladle-history/'
           , 'ladlewall_read'       
		   )



INSERT INTO [FrontEnd].[Menu]
           ([Parent]
           ,[Name]
           ,[RouteID]
           ,[SortOrder]
           ,[Enabled]
           ,[Visible]
           ,[RequiredRole]
           ,[Group]
          )
     VALUES
           (
		   (select top 1 Id from [frontend].[Menu] where [Name]='Ladles')
		   ,'Ladle History'
           ,@@IDENTITY
           ,1
           ,1
           ,1
           ,'ladlewall_read'
           ,NULL
           )
GO



USE IHBoxSystem

IF DATABASE_PRINCIPAL_ID('ladlewall_read') IS NULL
BEGIN
	CREATE ROLE ladlewall_read;
end
go


declare @id int
select top 1 @id =id from security.modules where [Name] = 'Ladle Wall'

insert into [Security].[ModuleActions] (ModuleID,Code,[Name],[Role])
values (@id,'read','Read','ladlewall_read')



go


EXEC sp_addextendedproperty  @level0type = N'USER' ,@level0name = [ladlewall_read] ,@name = N'securedsp-LAD.GetLadleEquipmentHistory'   ,@value =  null
EXEC sp_addextendedproperty  @level0type = N'USER' ,@level0name = [ladlewall_read] ,@name = N'securedsp-LAD.GetCurrentEquipment'		,@value =  null
EXEC sp_addextendedproperty  @level0type = N'USER' ,@level0name = [ladlewall_read] ,@name = N'securedsp-LAD.GetLadles'					 ,@value =  null
EXEC sp_addextendedproperty  @level0type = N'USER' ,@level0name = [ladlewall_read] ,@name = N'securedsp-LAD.GetEquipmentsPerType'    ,@value =  null  



update FrontEnd.Routes
	set [Route] = '!/ladle-history(/:start)(/:end)(/:ladleId)'
where ModuleName = 'ladle-history'
